Re: rename primary key - Mailing list pgsql-sql

From Ian Barwick
Subject Re: rename primary key
Date
Msg-id 1d581afe1001141934x2c525992w2e4bcf40a3113207@mail.gmail.com
Whole thread Raw
In response to rename primary key  (Seb <spluque@gmail.com>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Seb
Date:
Subject: rename primary key
Next
From: Seb
Date:
Subject: Re: rename primary key