Re: rename primary key

From: Ian Barwick <barwick(at)gmail(dot)com>
To: Seb <spluque(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: rename primary key
Date: 2010-01-15 03:34:15
Message-ID: 1d581afe1001141934x2c525992w2e4bcf40a3113207@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

2010/1/15 Seb <spluque(at)gmail(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Seb 2010-01-15 03:39:23 Re: rename primary key
Previous Message Seb 2010-01-15 03:28:23 rename primary key