Search code examples
postgresqldatabase-designdata-warehousesqldatatypes

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


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


Solution

  • 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