what is the right data type for unique key in postgresql DB?

socksocket picture socksocket · Aug 2, 2012 · Viewed 17.8k times · Source

which data type should I choose for a unique key (id of a user for example) in postgresql database's table?
does bigint is the one?

thanks

Answer

Mark Loiseau picture Mark Loiseau · Aug 2, 2012

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