Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tqzx0-00DJjK-9c for pgsql-general@arkaria.postgresql.org; Sat, 08 Mar 2025 19:35:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tqzwz-007Fg8-0y for pgsql-general@arkaria.postgresql.org; Sat, 08 Mar 2025 19:35:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tqzwy-007FcL-L4 for pgsql-general@lists.postgresql.org; Sat, 08 Mar 2025 19:35:08 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tqzwv-001jMh-0t for pgsql-general@lists.postgresql.org; Sat, 08 Mar 2025 19:35:08 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-2c1c4e364c8so1357609fac.1 for ; Sat, 08 Mar 2025 11:35:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741462505; x=1742067305; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=NtLip2EOo1ANxS3BGeVTXydKgUZOSxNRVwOyxZ8e1iA=; b=go9emSlgGL+OvRmWI9J4HyqfXgz9o+U1d70MF0cx7pcRogXEzvAmL3SFwjigwQk2sk HmptqxMesiG0jBRi3+A1QB2aIi0z52Hyp7NYL2C/qbCKTsfbGTbwim3b75SK8X/7cjsL iCj/lFJgApEcxzCKACBuSdCTEtzED0JNpUItX7X22XPrkmjOe+vybcAIgYsbc6J1sKqH ZnAKsbHw2Ex/TdEzLxAXeXUgfnJcZGaeyVbj5JsOJKZpT7QfqOVzZ5YYCJ88AbhE6yzW XKOHLKQA3hXyAf7gEYU5cNNnxCxYPLVpmIw5sbaFejiwgPL+IJdMxejusjk/wQdUNIma +Frw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741462505; x=1742067305; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NtLip2EOo1ANxS3BGeVTXydKgUZOSxNRVwOyxZ8e1iA=; b=mTiYfNqRINFt1ruJS51aZ158uN1XMkKC67v/bVb9Tn4Z7QpLatFFapZvTVAiIuzekf 7e5L34QIqsb+fANWjj9yEnxH4TeKBcRms3inpFIMkzRyMIUKDfC09OWdZvjwX+xo3MbE EODbg9AwXZu8cjZzj/5qO/oZ0zAvpAXDYnLYrwILkgwGoISZe7MfX66H8/ejV9io8a9J wAWoQY3rhBS6KTxzIfgHb/zWMC2HV3kDMDHiCZbHDo3bUTgrNS1plmkED5fRW2g0/Yjy V+29DvrTTt5pq7PlnHjZbOav+6TC3XuaMxMt5Cp4jdmWi3vhD1eiSB4GVcoN3BeqvKeO h/RA== X-Gm-Message-State: AOJu0Yz8moI6pBjIs3o8r6KVRmNNcG+3VmtOL1Y5gCfig1OLfd/md5FM JC7bKhNyK+Zp2EJl0go5WsStEM+cF5fXjM+yCKwhwC4Zxm9kaNPNZehemCkUNFdvUvRZE3IVsFz Nqz3gaVT3A5q4jJDa0DThRBzL/CU= X-Gm-Gg: ASbGncvqaWhgsncmsIBOo5VdboB3pyoWR0Z4yF64x/oDweeYE/2EIn3XRIO+R8H1F97 dAMl5+TaKWw8/oP2fYRDqfAW48arjXjdHbpCTiXhSYNid68g99mFYyz686/KUnACn6tdZttL1Av 6rnjDssAkOvIwsDMQFcY6FARi46LZ6e67nRQE= X-Google-Smtp-Source: AGHT+IHLje1N3JWKxgYlYP/9zd9N+MGi2vCBi1IT66OvmgYrIP2jIs0fERRYFz8FnWS0BZ/Grado3zMxgaLpmL5ySIw= X-Received: by 2002:a05:6870:d114:b0:29e:37af:a943 with SMTP id 586e51a60fabf-2c2822242ebmr2459557fac.18.1741462504834; Sat, 08 Mar 2025 11:35:04 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "David G. Johnston" Date: Sat, 8 Mar 2025 12:34:28 -0700 X-Gm-Features: AQ5f1JpmbHd9593onSnE0yrkHeU_wC9IumGXWj5W5MwsxLI6bYUit4d20obBLTY Message-ID: Subject: Re: exclusion constraint question To: "Rhys A.D. Stewart" Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000fd8e05062fd9d576" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000fd8e05062fd9d576 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Mar 8, 2025 at 12:01=E2=80=AFPM Rhys A.D. Stewart wrote: > > CHECK (l_mug_id <> c_mug_id AND l_mug_id <> r_mug_id AND c_mug_id > <> r_mug_id), > EXCLUDE USING gist (l_mug_id WITH <>, c_mug_id WITH <>, r_mug_id > WITH <>) -- Not working as expected (or my expectations are wrong). > ); > > And some data: > > INSERT INTO shelves VALUES (1, 7, 2, 1); > INSERT INTO shelves VALUES (2, 3, null, null); > INSERT INTO shelves VALUES (3, null, 1, 4); > INSERT INTO shelves VALUES (4, 4, 5, null); > > Any suggestions would be appreciated. > > Using "equals" or "not equals" when one of the inputs can be null is not usually what you want to do. The comparison evaluates to NULL which the constraint allows. David J. --000000000000fd8e05062fd9d576 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sat, Mar 8, 2025 at 12:01=E2=80=AFPM Rhys A.D. Stewart = <rhys.stewart@gmail.com>= ; wrote:

=C2=A0 =C2=A0 CHECK (l_mug_id <> c_mug_id AND l_mug_id <> r_mug= _id AND c_mug_id
<> r_mug_id),
=C2=A0 =C2=A0 EXCLUDE USING gist (l_mug_id WITH <>, c_mug_id WITH <= ;>, r_mug_id
WITH <>) -- Not working as expected (or my expectations are wrong). );

And some data:

INSERT INTO shelves VALUES (1,=C2=A0 =C2=A0 7,=C2=A0 =C2=A0 2,=C2=A0 =C2=A0= 1);
INSERT INTO shelves VALUES (2,=C2=A0 =C2=A0 3, null, null);
INSERT INTO shelves VALUES (3, null,=C2=A0 =C2=A0 1,=C2=A0 =C2=A0 4);
INSERT INTO shelves VALUES (4,=C2=A0 =C2=A0 4,=C2=A0 =C2=A0 5, null);

Any suggestions would be appreciated.


Using "equals" or "not equals" when one of the inputs = can be null is not usually what you want to do.=C2=A0 The comparison evalua= tes to NULL which the constraint allows.

David J.

--000000000000fd8e05062fd9d576--