Re: ALTER TABLE follow up

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Tom Haddon" <tom(at)betterhealthfoundation(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: ALTER TABLE follow up
Date: 2002-08-07 02:02:09
Message-ID: GNELIHDDFBOCMGBFGEFOCEIPCDAA.chriskl@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Tom,

> A follow up to the ALTER TABLE question last week. I had asked why I was
> getting an error message using the ALTER TABLE to add a PRIMARY
> KEY, and was
> told that this wasn't supported in 7.1.x. I've upgraded to 7.2.1 and now
> when I use the following SQL:
>
> ALTER TABLE "agency_contact_info" ADD CONSTRAINT
> "agency_contact_info_pkey"
> PRIMARY KEY NOT NULL ("id");

I have no idea where you got that NOT NULL bit from - it's not in the
manual. In fact Posgres 7.2 has no sql function for changing the null
status of a column. You can manually twiddle the catalogs however - make
SURE there's no NULL values in the column first:

UPDATE pg_attribute SET attnotnull = true WHERE attrelid = (SELECT oid FROM
pg_class WHERE relname = 'agency_contact_info') AND attname = 'id';

Now just go:

ALTER TABLE agency_contact_info ADD PRIMARY KEY (id):

Chris

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message cnliou 2002-08-07 03:29:50 Limit A Table To 1 Row
Previous Message Tom Haddon 2002-08-06 22:41:08 ALTER TABLE follow up