Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSql storing a value as integer vs varchar

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

In terms of lookup speed should I use bigint or varchar?

Additionally, if it's populated with millions of records will the different data types have any impact on storage?

like image 737
Dhanushka Amarakoon Avatar asked Feb 12 '16 09:02

Dhanushka Amarakoon


1 Answers

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

like image 171
Mureinik Avatar answered Oct 24 '22 22:10

Mureinik