Re: dropping an index

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Shuying Wang <wang(dot)shuying(dot)lists(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: dropping an index
Date: 2006-03-01 05:25:56
Message-ID: 20060301052556.GA16819@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, Mar 01, 2006 at 04:11:07PM +1100, Shuying Wang wrote:
> Is it possible to drop and recreate an index on a column that's
> actually a primary key for a table in PostgreSQL 7.3 ? I couldn't
> figure that out from the documentation.

You can use ALTER TABLE to drop and later add the primary key
constraint. Is that what you mean?

http://www.postgresql.org/docs/7.3/interactive/sql-altertable.html

test=> CREATE TABLE foo (id integer PRIMARY KEY);
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
Indexes: foo_pkey primary key btree (id)

test=> ALTER TABLE foo DROP CONSTRAINT foo_pkey;
ALTER TABLE
test=> \d foo
Table "public.foo"
Column | Type | Modifiers
--------+---------+-----------
id | integer | not null

test=> ALTER TABLE foo ADD PRIMARY KEY (id);
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo'
ALTER TABLE
test=> \d foo
Table "public.foo"
Column | Type | Modifiers
--------+---------+-----------
id | integer | not null
Indexes: foo_pkey primary key btree (id)

--
Michael Fuhr

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2006-03-01 06:33:22 Re: dropping an index
Previous Message Shuying Wang 2006-03-01 05:11:07 dropping an index