check contraint allows illegal value?

Started by Lee Harrover 24 years ago2 messagesbugs
Jump to latest
#1Lee Harr
missive@frontiernet.net

Is this a bug?

create table foo( c char(2)
check (c in ('09', '10', '11', '12', 'n/a'))
);
CREATE

insert into foo values('09');
INSERT

insert into foo values('10');
INSERT

insert into foo values('08');
ExecAppend: rejected due to CHECK constraint foo_c

insert into foo values('n/a');
ExecAppend: rejected due to CHECK constraint foo_c

clearly this was a 'whups' on my part, but it would have
been nice to know that my constraint was bogus at the
time the table was created.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Lee Harr (#1)
Re: check contraint allows illegal value?

missive@frontiernet.net (Lee Harr) writes:

Is this a bug?

create table foo( c char(2)
check (c in ('09', '10', '11', '12', 'n/a'))
);

I don't think so; at least, I don't think there's any way in the general
case for the system to realize that some part of a check condition can
never succeed or never fail. (See "halting problem".)

regards, tom lane