Skip site navigation (1) Skip section navigation (2)

Setting a pre-existing index as a primary key

From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Setting a pre-existing index as a primary key
Date: 2008-04-09 00:00:27
Message-ID: 36e682920804081700n3ef85bafx54a1c9f431532a10@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Hey all,

I've run into a couple cases now where it would be helpful to easily
assign an already-existing unique index as a primary key.  Unless I
completely missed something, there's no way to do this now without a
bit of catalog hackery.

My implementation idea is as follows:

Proposed Syntax (based on Oracle's syntax)

ALTER TABLE foo ADD CONSTRAINT bar PRIMARY KEY USING INDEX schema.tablename;

Proposed Implementation

1. Verify that the index named is a unique index
2. Check index columns for NOT NULL constraints
3. If indexed columns are not already NOT NULL, apply NOT NULL
4. If NOT NULL succeeds, complete the operation (catalogs,
dependencies, ...), else bail out.

Any comments, ideas, suggestions?

-- 
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
499 Thornall Street, 2nd Floor | jonah(dot)harris(at)enterprisedb(dot)com
Edison, NJ 08837 | http://www.enterprisedb.com/

Responses

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2008-04-09 00:06:11
Subject: Re: [PATCHES] libpq type system 0.9a
Previous:From: Andrew ChernowDate: 2008-04-08 23:45:27
Subject: Re: [PATCHES] libpq type system 0.9a

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group