From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Jitendra Loyal <jitendra.loyal@gmail.com>
To: 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:47:34 +0100
Message-ID: <698d0c84-ff8a-4197-51d4-0a9772b998dd@enterprisedb.com> (raw)
In-Reply-To: <CAGBkuscy+YehMzqAmhijQrQ37yhDAMSaWQ+rJJMmA1zWN_3ZaA@mail.gmail.com>
References: <CAGBkusdqR7ZuovjZmqCwN913=PRCTmnUjT3KdEyXCr3z74BNoQ@mail.gmail.com>
<CANNMO+L_8KePx6Svj2kFOd1RHnWZTMy7_-KXq+sJDHLM8gPinw@mail.gmail.com>
<CAGBkuscy+YehMzqAmhijQrQ37yhDAMSaWQ+rJJMmA1zWN_3ZaA@mail.gmail.com>
On 11/11/20 10:06 AM, Jitendra Loyal 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.
>
This has nothing to do with IS [NOT] NULL, it's the first part of the
expression (b = TRUE) causing trouble. Essentially, the constraint
(b = true) and (c is not null)
is evaluated in two steps. First we evaluate the two parts individually,
and for (null, true) the results would look like this:
(b = true) => null
(c is not null) => true
and then we combine those results using 'AND'
null AND true => null
which is considered as if the constraint matches. If you want to handle
NULL for the first expression, you may do this, for example:
(b it not null and b = true) and (c is not null)
Or something like that.
regards
--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
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: tomas.vondra@enterprisedb.com, jitendra.loyal@gmail.com, samokhvalov@gmail.com
Subject: Re: Check constraints do not seem to be working!!!
In-Reply-To: <698d0c84-ff8a-4197-51d4-0a9772b998dd@enterprisedb.com>
References: <CAGBkusdqR7ZuovjZmqCwN913=PRCTmnUjT3KdEyXCr3z74BNoQ@mail.gmail.com> <CANNMO+L_8KePx6Svj2kFOd1RHnWZTMy7_-KXq+sJDHLM8gPinw@mail.gmail.com> <CAGBkuscy+YehMzqAmhijQrQ37yhDAMSaWQ+rJJMmA1zWN_3ZaA@mail.gmail.com> <698d0c84-ff8a-4197-51d4-0a9772b998dd@enterprisedb.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