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.96) (envelope-from ) id 1vdbwo-002kZj-2G for pgsql-general@arkaria.postgresql.org; Wed, 07 Jan 2026 22:24:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdbwn-00FrHQ-1X for pgsql-general@arkaria.postgresql.org; Wed, 07 Jan 2026 22:24:10 +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.96) (envelope-from ) id 1vdbwn-00FrHI-0Q for pgsql-general@lists.postgresql.org; Wed, 07 Jan 2026 22:24:09 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vdbwl-0059n4-0C for pgsql-general@postgresql.org; Wed, 07 Jan 2026 22:24:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 607MO1sa1857031; Wed, 7 Jan 2026 17:24:01 -0500 From: Tom Lane To: Stuart Campbell cc: Laurenz Albe , pgsql-general@postgresql.org Subject: Re: Unexpected modification of check constraint definition In-reply-to: References: <1fa24f41862f214b44bcf94556db51c9946d28bd.camel@cybertec.at> Comments: In-reply-to Stuart Campbell message dated "Thu, 08 Jan 2026 08:55:50 +1100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1857029.1767824641.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Wed, 07 Jan 2026 17:24:01 -0500 Message-ID: <1857030.1767824641@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Stuart Campbell writes: > On Wed, Jan 7, 2026 at 11:57 PM Laurenz Albe > wrote: >> That implicit cast is made explicit when the parsed binary form of the >> constraint expression is >> reverse engineered to a string during "pg_dump". > Makes sense. For context, in pg_dump we are quite concerned that the dumped form of the expression be interpreted the same way when reloaded, so that's why implicit casts get made explicit. (The worry is mainly that the destination server could have a different set of available operators or casting rules, so it might opt for some different interpretation of an underspecified expression.) This isn't a perfect rule, because the parser may behave subtly differently when faced with different input, but it's the best we've been able to do. > That seems reasonable. What mostly seemed unexpected was that the parsed > expression changed the second time. i.e. original expression -> rewritten > expression with explicit type casting -> rewritten expression with (even > more!) explicit type casting. Yeah, this is actually a pretty complicated case, because the parser decides that it ought to convert the IN to an "= ANY(ARRAY)" construct. That opens up the question of whether to cast at the level of the individual array elements, or at the level of the array as a whole. The heuristics for that get affected by what casts were in the original input. regards, tom lane