Using string for large number better than BIGINT? (postgresql)

746 views Asked by At

I'm working on a discord.py bot. I switching from sqlite3 to postgresql (specifically asyncpg) and I'm running into the error value out of int32 range when trying to store guild ids. I can solve this by using something like bigint, but I'm concerned about it taking up too much space? Would it be better to use a string instead?

[EDIT]: The numbers I'm using are 18 digits

1

There are 1 answers

4
Laurenz Albe On

Use bigint by all means.

18 digit numbers fit well into a bigint, and it takes only 8 bytes. A string will at least take a byte per character plus one byte TOAST header.

Also, bigint comparisons are supported by the hardware and are way faster.