When I write:
CREATE TABLE accounts (
username varchar(64) PRIMARY KEY,
I get primary key named:
accounts_pkey
Is it possible to assign my own custom name, for instance “accounts_primary_key”?
Same story about UNIQUE.
I couldn’t find it in PostgreSQL documentation.
Thanks in advance.
The trick is the
CONSTRAINTpart in thecolumn_constraintsection ofCREATE TABLE. Example:This works for all kind of constraints, including
PRIMARY KEYandUNIQUE.See the docs of CREATE TABLE for details.