Re: How to drop a NOT NULL column constraint?

From: "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net>
To: Ed Loehr <eloehr(at)austin(dot)rr(dot)com>
Cc: pggeneral <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to drop a NOT NULL column constraint?
Date: 2001-01-02 18:03:42
Message-ID: Pine.LNX.4.30.0101021300590.3397-100000@chapelperilous.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2 Jan 2001, Ed Loehr wrote:

> I have a table created like so:
>
> CREATE TABLE foo (
> id INTEGER NOT NULL
> ...
> );
>
> I need to alter the table to get rid of the "NOT NULL" constraint on the
> 'id' column. Can I do this using ALTER TABLE? Or do I have to
> dump/recreate/reload the table?
>
> I'm looking for something like "ALTER TABLE foo ALTER COLUMN id DROP NOT
> NULL", but the docs don't hint at it...

I don't think Postgres supports DROP CONSTRAINT in the ALTER TABLE
statement yet. You'll need to create a temp table with the same structure
but without the constaint and do a SELECT INTO to copy the data over, then
delete the old table and rename the new table to the old name.

-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Shah, shah! Ayatollah you so!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-01-02 18:04:23 Re: How to drop a NOT NULL column constraint?
Previous Message Ed Loehr 2001-01-02 17:54:55 How to drop a NOT NULL column constraint?