M
M
Maxim Alyukov2020-06-01 23:11:13
Django
Maxim Alyukov, 2020-06-01 23:11:13

What's the difference between different IntegerField?

Good evening. I am learning Django. Can you please tell me what is the difference between BigIntegerField , PositiveIntegerField , SmallIntegerField , IntegerField and other type fields?

UPD: how does this affect the database and what is the benefit of using specific field types?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2020-06-01
@mvxmvl

UPD: how does this affect the database and what is the benefit of using specific field types?

If PostgreSQL is used, then it is written about these data types:
Type integer (4 bytes - range from -2147483648 to +2147483647) - the usual choice, giving a balance between range, space and performance. The smallint type (2 bytes, range -32768 to +32767) is usually used when saving disk space is needed. The bigint type (8 bytes, range -9223372036854775808 to 9223372036854775807) should only be used if the integer range is not enough, since integer fetches are much more performant.
And, accordingly, Positive... should be used in cases where you use only positive numbers - for example, product codes, in order to avoid errors.

S
Stepan Krapivin, 2020-06-01
@xevin

BigIntegerField can store values ​​from -9223372036854775808 to 9223372036854775807
PositiveIntegerField only positive numbers from 0 to 2147483647
SmallIntegerField values ​​from -32768 to 32767
IntegerField values ​​from -2147483648 to 2147483647

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question