Re: Check constraints do not seem to be working!!! - Mailing list pgsql-general

From Chris Sterritt
Subject Re: Check constraints do not seem to be working!!!
Date
Msg-id b9a52a3a-1a25-bb35-4298-58ce73af898a@yobota.xyz
Whole thread Raw
In response to Check constraints do not seem to be working!!!  (Jitendra Loyal <jitendra.loyal@gmail.com>)
Responses Re: Check constraints do not seem to be working!!!  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general


On 11/11/2020 06:44, Jitendra Loyal wrote:
Consider this table definition:
         create table t ( i serial, b bool, c bool,
                                constraint b_c check ( (b = true and c is not null ) or (b is distinct
from true and c is null) )
                                constraint b_c check ( (b = true and c is not null ) or (b = false and c
is null) or (b is null and c is null) )
                                );
Despite the above two constraints, the following rows get into the table:
     insert into t (b , c) values (null, true), (null, false); 


(b = TRUE AND c IS NOT NULL) evaluates to null when b is null

Cheers, 
Chris Sterritt

pgsql-general by date:

Previous
From: Jitendra Loyal
Date:
Subject: Check constraints do not seem to be working!!!
Next
From: Pavel Stehule
Date:
Subject: Re: Check constraints do not seem to be working!!!