Re: Potential bug in ALTER TABLE? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Potential bug in ALTER TABLE?
Date
Msg-id 23541.1062685145@sss.pgh.pa.us
Whole thread Raw
In response to Potential bug in ALTER TABLE?  (Jeroen Ruigrok/asmodai <asmodai@wxs.nl>)
List pgsql-hackers
Jeroen Ruigrok/asmodai <asmodai@wxs.nl> writes:
> just want to verify first with you guys before dumping it on the bugs
> list.  Most likely I am just being silly here or something.

The ALTER ADD CONSTRAINT form creates a table constraint, ie, one that's
not attached to any particular column.  If you write the constraint in
the CREATE TABLE as a table constraint, then you get the same result as
with ALTER ADD CONSTRAINT.

regression=# create table blah (name TEXT, CHECK (name IN ('blah', 'bleh')));
CREATE TABLE
regression=# \d blah   Table "public.blah"Column | Type | Modifiers
--------+------+-----------name   | text |
Check constraints:   "$1" CHECK ((name = 'blah'::text) OR (name = 'bleh'::text))


If you don't like the automatically generated name, assign your own...

regression=# ALTER TABLE blah ADD CONSTRAINT fooey CHECK (name IN ('blah', 'bleh'));
ALTER TABLE
regression=# \d blah   Table "public.blah"Column | Type | Modifiers
--------+------+-----------name   | text |
Check constraints:   "$1" CHECK ((name = 'blah'::text) OR (name = 'bleh'::text))   "fooey" CHECK ((name = 'blah'::text)
OR(name = 'bleh'::text))
 

        regards, tom lane


pgsql-hackers by date:

Previous
From: Jeroen Ruigrok/asmodai
Date:
Subject: Potential bug in ALTER TABLE?
Next
From: Andrew Dunstan
Date:
Subject: Re: Potential bug in ALTER TABLE?