Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcng4-0000Yf-Vy for pgsql-general@arkaria.postgresql.org; Wed, 11 Nov 2020 10:48:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kcng3-0004tv-U2 for pgsql-general@arkaria.postgresql.org; Wed, 11 Nov 2020 10:48:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcng3-0004tn-Ip for pgsql-general@lists.postgresql.org; Wed, 11 Nov 2020 10:48:35 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kcng1-0000L1-2k for pgsql-general@lists.postgresql.org; Wed, 11 Nov 2020 10:48:35 +0000 Received: by mail-ej1-x62a.google.com with SMTP id o9so2160565ejg.1 for ; Wed, 11 Nov 2020 02:48:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=96So/Icds8aO958ySXuvdzf99E/i3i19ZoUNkDN0FRA=; b=e9HDBYCWh1Nbr16JRAOPtFH8UG0g6JmhYTKLoV90CO2jE9ih8Pl5giypdWPVxw2b3g rbk8Hl0XR77a8eoL8IPZ97zwJ9lV1qIyv6nsyT8rAiM7PYiNachmf8OiJWdAmHSt8xzm KW0Zf79q9O7zwdbbGS+IvACqQM55Ic6JislhpJgDBNegEvcw7YR6zemfLh/d7S5Qlr+d J/qiONSr6G+AbSWsNIwoYox83P/7NUa8EuSNV7Cm22UbIVvKC7nI7UFyLQ9cew1R60Uj c/CLZ9vBgEQ2CSI22uXJIkhstN/Fv0N6L+BNm44jvotvsXrJsZBAqe35GATiVJih9JVW 4V2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=96So/Icds8aO958ySXuvdzf99E/i3i19ZoUNkDN0FRA=; b=duzjAgsi56kMvsPdE53KN6h7XaPJEYkkQjBR/cPIrSJ4vMcekXb9Z+UMspe99Aq4dy K7IlgqD8bHmxoKnDjHuSlV5BbMnD2nQxYWWqgVnaIZZaMk1AMa2Uo2WnIfvIuYNgwTH0 Oh/Rvr+k6jIWWRFEHPz8Eck3jqE86wm/5Wmmg9BWJz3zImpaNKDyG1eXLPCekp8HRGWP 7r+cW/mQFVAEqGlRHvfleevcL2yk7mnbmXigbf0uUIFTFRptxmSDjTxoURGu66StroCJ kYd3ukvgJDCqDtdHLeFHiuDZ+PbE+x9H3x/l1ldz121bdIa2s2VGgkU3IZ9zrOZyteN/ L9jA== X-Gm-Message-State: AOAM531EjFzjeHGsl3UiUHWSt2mpU1uUmbDA44H4LT/v2oewu1nNMzPg VnM7FFrDWOq9tOVG4dtM/0A= X-Google-Smtp-Source: ABdhPJwXOtLe+wDWJ/lWWg5Qy4fGeCpxtQAeZAJetBvFzP3c5gewO1YHmjk51DbpoUTJCDiegZoEPA== X-Received: by 2002:a17:906:5f89:: with SMTP id a9mr24027293eju.262.1605091712239; Wed, 11 Nov 2020 02:48:32 -0800 (PST) Received: from [10.236.150.223] (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id h22sm719397ejt.21.2020.11.11.02.48.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Nov 2020 02:48:31 -0800 (PST) Content-Type: multipart/alternative; boundary=Apple-Mail-1298C40E-C641-4F59-A73D-785656E375CA Content-Transfer-Encoding: 7bit From: Alban Hertroys Mime-Version: 1.0 (1.0) Subject: Re: Check constraints do not seem to be working!!! Date: Wed, 11 Nov 2020 11:48:30 +0100 Message-Id: References: Cc: Nikolay Samokhvalov , pgsql-general@lists.postgresql.org In-Reply-To: To: Jitendra Loyal X-Mailer: iPad Mail (18B92) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail-1298C40E-C641-4F59-A73D-785656E375CA Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11 Nov 2020, at 11:15, Jitendra Loyal wrote: >=20 > =EF=BB=BF > Thanks Nikolay >=20 > I read that but is there a way to meet the above requirement. And I will l= ike 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 docume= nt. -- 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, w= rote: >>> On Wed, Nov 11, 2020 at 12:26 AM Jitendra Loyal wrote: >>> Despite the above two constraints, the following rows get into the table= : >>> insert into t (b , c) values (null, true), (null, false); =20 >>=20 >> This behavior is described in the docs https://www.postgresql.org/docs/cu= rrent/ddl-constraints.html#DDL-CONSTRAINTS-CHECK-CONSTRAINTS: >>=20 >> > It should be noted that a check constraint is satisfied if the check ex= pression evaluates to true or the null value. Since most expressions will ev= aluate to the null value if any operand is null, they will not prevent null v= alues in the constrained columns. To ensure that a column does not contain n= ull values, the not-null constraint described in the next section can be use= d. --Apple-Mail-1298C40E-C641-4F59-A73D-785656E375CA Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On 11 Nov 2020, at 11:15, Jitendra Loya= l <jitendra.loyal@gmail.com> wrote:

=EF=BB=BF
Thanks Nikolay

I read that but is there a way to meet the above requirement. An= d I will like to add that IS NULL and IS NOT NULL should evaluate to true/fa= lse. 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 valu= es, 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 n= o forest.

On Wed 11 Nov, 2020= , 14:18 Nikolay Samokhvalov, <samokhvalov@gmail.com> wrote:
<= /div>
On Wed,= Nov 11, 2020 at 12:26 AM Jitendra Loyal <jitendra.loyal@= gmail.com> wrote:
Despi= te the above two constraints, the following rows get into the table:<= br style=3D"font-family:Arial,Helvetica,sans-serif">     insert into t (b , c) val= ues (null, true), (null, false);  


> It should be noted that a c= heck constraint is satisfied if the check expression evaluates to true or th= e null value. Since most expressions will evaluate to the null value if any o= perand 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 constra= int described in the next section can be used.
= --Apple-Mail-1298C40E-C641-4F59-A73D-785656E375CA--