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

Viewed 26121

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

3 Answers

According to this answer the current recommended approach to doing auto-increment unique IDs is to use the generated as identity syntax instead of serial.

Here's an example:

-- the old way
create table t1 (id serial primary key);

-- the new way
create table t2 (id integer primary key generated always as identity);
Related