PostgreSql saves value as integer vs varchar

I want to save a 15 digit number in a table.

In terms of search speed should use bigintor varchar?

Also, if it is filled with millions of records, will different types of data have any effect on the repository?

+4
source share
2 answers

In terms of a space, a biginttakes up 8 bytes, and a 15-character string takes up to 19 bytes (4 bytes and up to 15 bytes for data), depending on its value. Also, generally speaking, equality checks should be slightly faster for numerical operations. Other than that, it depends a lot on what you are going to do with this data. If you intend to use numerical / mathematical operations or a query according to ranges, you should use bigint.

+7
source

You can store them as BIGINT, since comparison using INT is faster compared to varchar. I would also suggest creating an index on a column if you expect millions of records to speed up data retrieval.

You can also check out this forum :

. Char, , (). VARCHAR - , , .

, , CHAR [x] , VARCHARS.

+2

Source: https://habr.com/ru/post/1628468/


All Articles