pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alban Hertroys <haramrae@gmail.com>
To: Jitendra Loyal <jitendra.loyal@gmail.com>
Cc: Nikolay Samokhvalov <samokhvalov@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Check constraints do not seem to be working!!!
Date: Wed, 11 Nov 2020 11:48:30 +0100
Message-ID: <F5D6BBA6-ACFB-42B4-A335-143E8F90F9F0@gmail.com> (raw)
In-Reply-To: <CAGBkuscy+YehMzqAmhijQrQ37yhDAMSaWQ+rJJMmA1zWN_3ZaA@mail.gmail.com>
References: <CAGBkuscy+YehMzqAmhijQrQ37yhDAMSaWQ+rJJMmA1zWN_3ZaA@mail.gmail.com>


On 11 Nov 2020, at 11:15, Jitendra Loyal <jitendra.loyal@gmail.com> wrote:
> 
> 
> Thanks Nikolay
> 
> I read that but is there a way to meet the above requirement. And I will like to add that IS NULL and IS NOT NULL should evaluate to true/false. These operators are made for this and should not be returning NULL.

That is exactly what they do. Your problem is with the equality operator and its behaviour with NULL values, which is described in the referenced document.

--
If you can't see the forest for the trees,
Cut the trees and you'll find there is no forest.

>> On Wed 11 Nov, 2020, 14:18 Nikolay Samokhvalov, <samokhvalov@gmail.com> wrote:
>>> On Wed, Nov 11, 2020 at 12:26 AM Jitendra Loyal <jitendra.loyal@gmail.com> wrote:
>>> Despite the above two constraints, the following rows get into the table:
>>>      insert into t (b , c) values (null, true), (null, false);  
>> 
>> This behavior is described in the docs https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-CHECK-CONSTRAINTS:
>> 
>> > It should be noted that a check constraint is satisfied if the check expression evaluates to true or the null value. Since most expressions will evaluate to the null value if any operand is null, they will not prevent null values in the constrained columns. To ensure that a column does not contain null values, the not-null constraint described in the next section can be used.

view thread (10+ messages)  latest in thread

Message-ID: <F5D6BBA6-ACFB-42B4-A335-143E8F90F9F0@gmail.com>
Permalink:  ../F5D6BBA6-ACFB-42B4-A335-143E8F90F9F0@gmail.com/
Also on:    postgresql.org/message-id/F5D6BBA6-ACFB-42B4-A335-143E8F90F9F0@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: haramrae@gmail.com, jitendra.loyal@gmail.com, samokhvalov@gmail.com
  Subject: Re: Check constraints do not seem to be working!!!
  In-Reply-To: <F5D6BBA6-ACFB-42B4-A335-143E8F90F9F0@gmail.com>
  References: <CAGBkuscy+YehMzqAmhijQrQ37yhDAMSaWQ+rJJMmA1zWN_3ZaA@mail.gmail.com> <F5D6BBA6-ACFB-42B4-A335-143E8F90F9F0@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox