PostgreSQL: is it possible to provide a custom name for PRIMARY KEY or UNIQUE?

When I write:

CREATE TABLE accounts ( username varchar(64) PRIMARY KEY, 

I get a primary key with the name:

 accounts_pkey 

Can I assign my own username, for example, "accounts_primary_key"?

The same story about UNIQUE .

I could not find it in the PostgreSQL documentation.

Thanks in advance.

+10
indexing postgresql constraints primary-key unique-key
Dec 29 '11 at 23:11
source share
1 answer

Focus in CONSTRAINT under column_constraint CREATE TABLE . Example:

 > create table x(xx text constraint xxxx primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "xxxx" for table "x" CREATE TABLE 

This works for all types of constraints, including PRIMARY KEY and UNIQUE .

See the CREATE TABLE docs for more details.

+13
Dec 29 '11 at 11:21
source share



All Articles