Re: Potential bug in ALTER TABLE?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeroen Ruigrok/asmodai <asmodai(at)wxs(dot)nl>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Potential bug in ALTER TABLE?
Date: 2003-09-04 14:19:05
Message-ID: 23541.1062685145@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jeroen Ruigrok/asmodai <asmodai(at)wxs(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2003-09-04 14:24:37 Re: Potential bug in ALTER TABLE?
Previous Message Jeroen Ruigrok/asmodai 2003-09-04 14:02:19 Potential bug in ALTER TABLE?