Re: dropping an index - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: dropping an index
Date
Msg-id 20060301052556.GA16819@winnie.fuhr.org
Whole thread Raw
In response to dropping an index  ("Shuying Wang" <wang.shuying.lists@gmail.com>)
Responses Re: dropping an index  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-novice by date:

Previous
From: "Shuying Wang"
Date:
Subject: dropping an index
Next
From: Tom Lane
Date:
Subject: Re: dropping an index