2010/1/15 Seb <spluque@gmail.com>:
> Hi,
>
> Is it possible to rename a primary key?  I learnt that to rename foreign
> keys one has to drop it and recreate with the new name, or add a new new
> and drop the old one.  What is the approach for primary keys?  Thanks.
Is this what you mean?
psql (8.4.2)
You are now connected to database "test".
test=# CREATE TABLE foo (id serial primary key);
NOTICE:  CREATE TABLE will create implicit sequence "foo_id_seq" for
serial column "foo.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"foo_pkey" for table "foo"
CREATE TABLE
test=# \d foo                        Table "public.foo"Column |  Type   |                    Modifiers
--------+---------+--------------------------------------------------id     | integer | not null default
nextval('foo_id_seq'::regclass)
Indexes:   "foo_pkey" PRIMARY KEY, btree (id)
test=# ALTER INDEX foo_pkey RENAME to bar_fkey;
ALTER INDEX
test=# \d foo                        Table "public.foo"Column |  Type   |                    Modifiers
--------+---------+--------------------------------------------------id     | integer | not null default
nextval('foo_id_seq'::regclass)
Indexes:   "bar_fkey" PRIMARY KEY, btree (id)
test=#
Ian Barwick