From: Ian Barwick <barwick@gmail.com>
To: Seb <spluque@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: rename primary key
Date: Fri, 15 Jan 2010 12:34:15 +0900
Message-ID: <1d581afe1001141934x2c525992w2e4bcf40a3113207@mail.gmail.com> (raw)
In-Reply-To: <87hbqo11yg.fsf@kolob.sebmags.homelinux.org>
References: <87hbqo11yg.fsf@kolob.sebmags.homelinux.org>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: barwick@gmail.com, spluque@gmail.com
Subject: Re: rename primary key
In-Reply-To: <1d581afe1001141934x2c525992w2e4bcf40a3113207@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox