From: | "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | interesting check constraint behavior |
Date: | 2010-01-06 23:12:56 |
Message-ID: | 482E80323A35A54498B8B70FF2B879800438460277@azsmsx504.amr.corp.intel.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
thedb=# create table foo (col1 text, constraint chk check (col1 in ('a','b','c',null)));
CREATE TABLE
thedb=# insert into foo (col1) values ('xxx');
INSERT 0 1
Hmmmm... I would have thought that this would have violated the constraint because 'xxx' is not null and nit one of the allowed values.
Let's try again without that null...
thedb=# create table foo2 (col1 text, constraint chk check (col1 in ('a','b','c')));
CREATE TABLE
thedb=# insert into foo2 (col1) values ('xxx');
ERROR: new row for relation "foo2" violates check constraint "chk"
thedb=#
Getting rid of the "null" fixed it.
Is there a different way I can allow for a static set of values AND null too?
Thanks for any comments !!!
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2010-01-06 23:38:56 | Re: interesting check constraint behavior |
Previous Message | Tom Lane | 2010-01-06 22:13:56 | Re: timestamp fields and order by? |