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 1xPzfB-000000014YF-44zz for pgsql-bugs@arkaria.postgresql.org; Sun, 08 Nov 2026 09:58:15 +0000 Received: from localhost ([127.0.0.1]:39208 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xPzfC-00000005zLa-0HiP for pgsql-bugs@arkaria.postgresql.org; Sun, 08 Nov 2026 09:58:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:43668) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPtac-00000005LE6-1bnA for pgsql-bugs@lists.postgresql.org; Sun, 08 Nov 2026 03:29:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPtaZ-00000000nox-2b9n for pgsql-bugs@lists.postgresql.org; Sun, 08 Nov 2026 03:29:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=9C1J+8YSzlJAoVWidWZNtEINLKfr5zV/N4b6r3ggJOM=; b=TJKyV5otD9oHRFpkvLKGLraeQk 0tjrhXnrzxWi92rirK/qSziNzw9+OTBehRPQAKQxBO1qxr76yjv11x9HX/+q4M200YfJGKbi3F7DC vVibiXWI55dEq+o+6BoC31QxGjd6bxuW94yQVuAMuMMc+OhfYgiOzrLdFNvBmffwvltVpyIMMjoTI WYjjEAfX/8i2GvBbNaUTR0GgH9TCG6n5FGXUrkRzBK85ARORqt0u0Uvgb1fNe0WZEDFGmyAQekP9p eoCw6L0vb5fNOVfwxlalV0QlAqHr1YxUqHDC/KhOsDDHmr9TnJMHhrx2xbKbDTBz9j35DeDBwQU1v NeRrb9bw==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPtaa-00000002Gc6-1yyQ for pgsql-bugs@lists.postgresql.org; Sun, 08 Nov 2026 03:29:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xPtaY-00000005ZVT-3yLR for pgsql-bugs@lists.postgresql.org; Sun, 08 Nov 2026 03:29:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19851: Adding a tautological CHECK(true) to a domain changes JSON_VALUE's result (silent NULL, value/type c To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Sun, 08 Nov 2026 03:28:37 +0000 Message-ID: <19851-f88328048ff9770a@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19851 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: Linux x86_64; platform-independent (reproduced ide Description: =20 **Description:** Two domains with the *identical value set* =E2=80=94 one declared without constraints, one with only a tautological `CHECK (true)` that can never reject anything =E2=80=94 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. Actual divergences (JSON boolean `true` as input, `RETURNING ` then cast to text for display): | RETURNING type | plain | domain (no constraint) | domain + CHECK(true) | |---|---|---|---| | text | `t` | `t` | **`true`** | | char(3) | `t` | `t` | **(NULL)** =E2=80=94 silent data loss | | jsonb | `true` | **(NULL)** | `true` | And for a string scalar with domains over jsonb: base `RETURNING jsonb` yields `"1"` (a JSON string), while both domains yield `1` (a JSON number) = =E2=80=94 a type change of the represented value. The official expected baseline is recorded in the regression suite (`sqljson_queryfuncs.out`): `JSON_VALUE(jsonb 'true', '$') =3D t`. **Root cause:** for a RETURNING type that is a domain, `DomainHasConstraints()` switches the coercion path inside `ExecEvalJsonExprPath` (use_io_coercion vs use_json_coercion), and the two paths represent the same scalar differently; the presence of any CHECK constraint =E2=80=94 even a tautology =E2=80=94 flips which path is taken. **Reproduction (self-contained SQL; verified identically on 18.6 and master):** ```sql CREATE DOMAIN d_txt_nc AS text; CREATE DOMAIN d_txt_ct AS text CHECK (true); CREATE DOMAIN d_ch_nc AS char(3); CREATE DOMAIN d_ch_ct AS char(3) CHECK (true); CREATE DOMAIN d_jb_nc AS jsonb; CREATE DOMAIN d_jb_ct AS jsonb CHECK (true); -- 0. official baseline: JSON boolean rendered to text SELECT JSON_VALUE(jsonb 'true', '$') AS base_text; -- t -- 1. per base type: plain / no-constraint domain / CHECK(true) domain must agree SELECT 'text' AS base, JSON_VALUE(jsonb 'true', '$' RETURNING text)::text AS plain, JSON_VALUE(jsonb 'true', '$' RETURNING d_txt_nc)::text AS dom_no_constr, JSON_VALUE(jsonb 'true', '$' RETURNING d_txt_ct)::text AS dom_check_true UNION ALL SELECT 'char(3)', JSON_VALUE(jsonb 'true', '$' RETURNING char(3))::text, JSON_VALUE(jsonb 'true', '$' RETURNING d_ch_nc)::text, JSON_VALUE(jsonb 'true', '$' RETURNING d_ch_ct)::text UNION ALL SELECT 'jsonb', JSON_VALUE(jsonb 'true', '$' RETURNING jsonb)::text, JSON_VALUE(jsonb 'true', '$' RETURNING d_jb_nc)::text, JSON_VALUE(jsonb 'true', '$' RETURNING d_jb_ct)::text; -- text: t | t | true -- char(3): t | t | (NULL) <- silent data loss -- jsonb: true| (NULL) | true -- 2. string scalar: domain (over jsonb) vs base jsonb SELECT JSON_VALUE(jsonb '"1"', '$' RETURNING jsonb) AS base_jsonb, -- "1" (JSON string) JSON_VALUE(jsonb '"1"', '$' RETURNING d_jb_nc) AS dom_no_constr,-- 1 (JSON number) JSON_VALUE(jsonb '"1"', '$' RETURNING d_jb_ct) AS dom_check_true;-- 1 ``` **Expected behavior:** the presence of a constraint must not change the coerced value: `CHECK(true)` never fails, so `d_*_nc` and `d_*_ct` have identical value sets and must return identical results; and a domain without constraints should behave like its base type. **Impact:** silent NULL (data loss) and value/type changes for `JSON_VALUE`/`JSON_QUERY` with domain RETURNING types; results become dependent on irrelevant metadata (whether the domain happens to carry any CHECK constraint), which also breaks views/CHECK constraints defined against such expressions after a domain is altered.