Re: Check constraints do not seem to be working!!!

From: Chris Sterritt <chris(dot)sterritt(at)yobota(dot)xyz>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Check constraints do not seem to be working!!!
Date: 2020-11-11 08:38:28
Message-ID: b9a52a3a-1a25-bb35-4298-58ce73af898a@yobota.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2020-11-11 08:41:30 Re: Check constraints do not seem to be working!!!
Previous Message Jitendra Loyal 2020-11-11 06:44:35 Check constraints do not seem to be working!!!