what is the right data type for unique key in postgresql DB?
bigint
(or bigserial
if you need auto-incrementing keys) is just fine.
If know for certain that you are not going to load too many rows, you might consider integer
(or a regular serial
) and potentially save some harddisk space.
Use the serial
type for automatically incrementing unique ids.
If you plan to have more than two billion entries, use bigserial
. serial
is the PostgresSQL equivalent of MySQL's AUTO_INCREMENT
.
PostgresSQL Documentation: Numeric Types