naming a primary key possible?

Started by Ow Mun Hengover 18 years ago4 messagesgeneral
Jump to latest
#1Ow Mun Heng
Ow.Mun.Heng@wdc.com

Is it possible to name a primary key (composite) primary key rather than
have pg default to table_name_pkey??

I tried something like

primary key pkey_table_short_form_name (a,b,c)

but it didnt' work.

#2Erik Jones
erik@myemma.com
In reply to: Ow Mun Heng (#1)
Re: naming a primary key possible?

On Aug 27, 2007, at 8:50 PM, Ow Mun Heng wrote:

Is it possible to name a primary key (composite) primary key rather
than
have pg default to table_name_pkey??

I tried something like

primary key pkey_table_short_form_name (a,b,c)

but it didnt' work.

Give this a shot:

CONTRAINT pkey_table_short_form_name PRIMARY KEY (a,b,c)

That's not really clear from the top of the CREATE TABLE docs but
there's an example at the bottom that shows it.

Erik Jones

Software Developer | Emma®
erik@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com

#3Michael Glaesemann
grzm@seespotcode.net
In reply to: Ow Mun Heng (#1)
Re: naming a primary key possible?

On Aug 27, 2007, at 20:50 , Ow Mun Heng wrote:

Is it possible to name a primary key (composite) primary key rather
than
have pg default to table_name_pkey??

I tried something like

primary key pkey_table_short_form_name (a,b,c)

create table tab (col text, constraint col_is_pkey primary key (col));

http://www.postgresql.org/docs/8.2/interactive/sql-createtable.html

Michael Glaesemann
grzm seespotcode net

#4Ow Mun Heng
Ow.Mun.Heng@wdc.com
In reply to: Erik Jones (#2)
Re: naming a primary key possible?

On Mon, 2007-08-27 at 21:03 -0500, Erik Jones wrote:

On Aug 27, 2007, at 8:50 PM, Ow Mun Heng wrote:

Is it possible to name a primary key (composite) primary key rather
than have pg default to table_name_pkey??

I tried something like

primary key pkey_table_short_form_name (a,b,c)

Give this a shot:

CONTRAINT pkey_table_short_form_name PRIMARY KEY (a,b,c)

That's not really clear from the top of the CREATE TABLE docs but
there's an example at the bottom that shows it.

This definitely works..
Thanks..

Indexes:
"trd_pkey" PRIMARY KEY, btree (trd_pkey)