check contraints incorrectly reject "null" - Mailing list pgsql-hackers

From Don Baccus
Subject check contraints incorrectly reject "null"
Date
Msg-id 3.0.1.32.19991209080050.00e553f0@mail.pacifier.com
Whole thread Raw
Responses Re: [HACKERS] check contraints incorrectly reject "null"
List pgsql-hackers
Given a table definition like:

create table foo (i integer check (i > 0));

I noticed the following works in Oracle but fails in Postgres:

insert into foo values(null);

I was curious about what the standard might say, and had been
meaning to buy Date's book for some time, so broke down and
did so.

According to Date, a check contraint should fail if the expression
evaluates to false.  It appears that Postgres only passes the
check constraint if it evaluates to true.  In three-valued logic,
these statements aren't equivalent.  He has a paragraph about
nulls and check contraints in chapter 14, I believe, and his
explanation makes it clear that Oracle is right, Postgres wrong.

It's easy to fix by adding a check for null to the constraint,
and afterwards the SQL still works with Oracle, but it's still
a bug...



- Don Baccus, Portland OR <dhogaza@pacifier.com> Nature photos, on-line guides, Pacific Northwest Rare Bird Alert
Serviceand other goodies at http://donb.photo.net.
 


pgsql-hackers by date:

Previous
From: Don Baccus
Date:
Subject: alter table crashes back end
Next
From: Don Baccus
Date:
Subject: Re: PostgreSQL front ends (was Re: [HACKERS] Parallel regress tests (was Re: FOREIGN KEY andshift/reduce))