Django, Big integer and url

Viewed 376

I was looking for the answer, but I couldn't find it. In PostgreSQL I have primary key, which is autofield which is BigInt type. In url path I have to reference it with something like "int:pk". If I use int for this purpose, will I fall in trouble later on, when numbers will exceed the limits of integer type? Which type I better use for bigint in url? It doesn't take BigInt or BigIntegerField, which are Django's type for bigint. Do I have to use patterns like <'$> instead of int? Thank you for the help!

1 Answers

You are okay to use int type in python, since in python 3.x the value of an integer is not restricted by the number of bits and can expand to the limit of the available memory. For Python2.x situation a little bit different, but still safe for you. Please look for quotes from documentation below:

Python 2.7:

Plain integers (also just called integers) are implemented using long in C, which gives them at least 32 bits of precision

https://docs.python.org/2.7/library/stdtypes.html#numeric-types-int-float-long-complex

Therefore for python 2.X the range is from -9223372036854775808 to 9223372036854775807 ( as long can store up to 64-bit)

Python 3.x:

Integers have unlimited precision.

https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex

For PostGreSQL BigInt can store up to 8 bytes, which is the same as for python2.x, therefore it's completely safe to proceed with the mapping of python int to PostGreSQL BigInt

Related