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