Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iehDn-0003uE-Nd for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Dec 2019 15:14:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iehDl-0001B6-WF for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Dec 2019 15:14:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iehDl-0001AK-Nr for pgsql-bugs@lists.postgresql.org; Tue, 10 Dec 2019 15:14:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iehDe-00084T-Lv for pgsql-bugs@lists.postgresql.org; Tue, 10 Dec 2019 15:14:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xBAFEVHj005140; Tue, 10 Dec 2019 10:14:32 -0500 From: Tom Lane To: pjander2@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16158: Check constraints using SQL functions work incorrectly In-reply-to: <16158-7ccf2f74b3d655db@postgresql.org> References: <16158-7ccf2f74b3d655db@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 10 Dec 2019 12:27:13 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5138.1575990871.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 10 Dec 2019 10:14:31 -0500 Message-ID: <5139.1575990871@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > Summary: I defined a check constraint `project_limits` using > [SQL functions](https://www.postgresql.org/docs/9.1/xfunc-sql.html). This is not a bug; you've ignored the restriction that check constraints must be immutable. See the "Notes" at the bottom of this section: https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAIN= TS-CHECK-CONSTRAINTS In the particular case at hand, I think the behavior you're complaining about stems from the fact that the CHECK condition is evaluated before the actual row insertion has happened. regards, tom lane