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.98.2) (envelope-from ) id 1xRcPC-000000017Yk-2WTv for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Nov 2026 21:32:27 +0000 Received: from localhost ([127.0.0.1]:47770 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xRcPB-00000004zj3-2LEx for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Nov 2026 21:32:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:51260) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xRcPB-00000004zit-1BTo for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 21:32:25 +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.98.2) (envelope-from ) id 1xRcP8-00000000kCs-43IO for pgsql-bugs@lists.postgresql.org; Thu, 12 Nov 2026 21:32:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 6ACLWJvi369195; Thu, 12 Nov 2026 16:32:19 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 sss.pgh.pa.us 6ACLWJvi369195 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sss.pgh.pa.us; s=default; t=1794519140; bh=f5kxTtzDuvACJCvXPAzv03NCz+6MPo6gMI6cxLY4Qpo=; h=From:To:cc:Subject:In-reply-to:References:Date:From; b=L8NgLdJ5WhSUTAea+RXpLZ61nDQXUevvlX8e7TxgZCOmNV9CdhNTllBNsdI86xN1U nAIZSRoJQKJioPg6IdtxX1gfPVWTOUBUXVsr58nXNv2KhjEUo+Dfn6hn/9xr0DRdi5 T856l7IMWlREWDsmKMsRNNpRvQeSeuZj3AqOmA9s= From: Tom Lane To: 303677365@qq.com cc: pgsql-bugs@lists.postgresql.org, Amit Langote Subject: Re: BUG #19851: Adding a tautological CHECK(true) to a domain changes JSON_VALUE's result (silent NULL, value/type c In-reply-to: <19851-f88328048ff9770a@postgresql.org> References: <19851-f88328048ff9770a@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sun, 08 Nov 2026 03:28:37 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <369193.1794519139.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 12 Nov 2026 16:32:19 -0500 Message-ID: <369194.1794519139@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Two domains with the *identical value set* — one declared without > constraints, one with only a tautological `CHECK (true)` that can never > reject anything — give *different results* for the same `JSON_VALUE` > expression. `CHECK(true)` is a no-op semantically, so the two results must > agree, and both must agree with the base type. Yeah, this is a mess. The entire design of JsonExpr in this area is a disaster, starting here: /* * Information about converting the result of jsonpath functions * JsonPathQuery() and JsonPathValue() to the RETURNING type. */ bool use_io_coercion; bool use_json_coercion; Possibly, if these flags hadn't been so utterly undocumented, transformJsonFuncExpr wouldn't be so confused about what it needs to do with domains. But there are worse problems. The broken logic is in parse_expr.c: if (get_typtype(jsexpr->returning->typid) == TYPTYPE_DOMAIN && DomainHasConstraints(jsexpr->returning->typid, NULL)) jsexpr->use_json_coercion = true; else jsexpr->use_io_coercion = true; Quite aside from whether this is the right thing, testing DomainHasConstraints *at parse time* is insane. The situation could be completely different by the time we execute the expression. At the earliest this decision should be made in the planner; but probably doing it at executor startup would be better. Another reason for doing it later is that we cannot fix the behavior in released versions given this structure: even if we end up still using exactly two booleans, any stored JsonExpr will already have locked down the values of these flags. What I'm contemplating as a potential fix design is to remove these flags in master, leave them present-but-unused in back branches, and adjust the runtime expression representation instead. I'm afraid now to look through the rest of the SQL/JSON logic for similar errors. regards, tom lane