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 1xAMgK-00000002bNG-0Eri for pgsql-bugs@arkaria.postgresql.org; Sat, 26 Sep 2026 07:18:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xAMgJ-00000003nom-1FBa for pgsql-bugs@arkaria.postgresql.org; Sat, 26 Sep 2026 07:18:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xALsK-00000003jXB-2Wjd for pgsql-bugs@lists.postgresql.org; Sat, 26 Sep 2026 06:27:08 +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 1xALsI-00000001JY8-1N9c for pgsql-bugs@lists.postgresql.org; Sat, 26 Sep 2026 06:27:07 +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=7C5Qhh2AB5k4KiXOTkFe5JDf798w42ssPVcwEx13Vks=; b=N2q89DBYWAKmOqAUYr/ghFZpzC Mcah3eKz1Aegx1FIWH7BMSB8kcHoue9atF974kBuBKunJmC9yFPGB8V1bEb8dUudV5S1p4ti3G5/Y DaXVW12PV2elw+Buc3Hvlk13j88SNWGAS522EXOW1rTPZYghFp1w95t2jE92dXD98E0WjYdm//eq/ T9jEm46DRNsans3joQ19m6EAOG3Rh/KdpuU85PFrHMWRCU0AT/WHb4pGTBaJEVlKwZpImmQ7ytTXf /VQ3sQonmWQ24YhxBbv2gCAOVT9+3NU8iqFt6FioWbjHTjFhpHnedd30/2zBAPw1olTYwbuPR7W6x dQzs0U1g==; 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.96) (envelope-from ) id 1xALsG-003tiv-0k for pgsql-bugs@lists.postgresql.org; Sat, 26 Sep 2026 06:27:06 +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 1xALsE-0000000BGmb-22fB for pgsql-bugs@lists.postgresql.org; Sat, 26 Sep 2026 06:27:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19721: json_value with DEFAULT ON ERROR returns inconsistent results for NULL input in materialized CTE To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 1482694023@qq.com Reply-To: 1482694023@qq.com, pgsql-bugs@lists.postgresql.org Date: Sat, 26 Sep 2026 06:26:06 +0000 Message-ID: <19721-6d5c523ab7ee25e4@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: 19721 Logged by: N J Email address: 1482694023@qq.com PostgreSQL version: 18.6 Operating system: windows 11 Description: =20 Environment: PostgreSQL: 18.6 OS: Windows 11 64-bit Reproduction SQL: CREATE TEMP TABLE json_requests ( request_id integer PRIMARY KEY, expected integer ); CREATE TEMP TABLE json_payloads ( request_id integer PRIMARY KEY REFERENCES json_requests(request_id), document jsonb NOT NULL ); INSERT INTO json_requests VALUES (1, 0), (2, NULL), (3, 7), (4, NULL); INSERT INTO json_payloads VALUES (1, '{}'::jsonb), (3, '{"a":7}'::jsonb); WITH ordered_inputs AS MATERIALIZED ( SELECT r.request_id, r.expected, p.document FROM json_requests AS r LEFT JOIN json_payloads AS p USING (request_id) ORDER BY r.request_id ), evaluated AS MATERIALIZED ( SELECT request_id, expected, json_value( document, 'strict $.a' RETURNING integer DEFAULT 0 ON ERROR ) AS actual FROM ordered_inputs ) SELECT request_id, expected, actual, actual IS DISTINCT FROM expected AS differs FROM evaluated ORDER BY request_id; Observed result: request_id | expected | actual | differs ------------+----------+--------+--------- 1 | 0 | 0 | f 2 | null | 0 | t 3 | 7 | 7 | f 4 | null | null| f Expected result: Rows 2 and 4 both have NULL document from the LEFT JOIN. The identical json_value expression should return the same result for both NULL inputs. Either both should return 0 (DEFAULT value) or both should return NULL. The current behavior is inconsistent. Explanation: The inconsistency occurs when using MATERIALIZED CTEs with json_value and DEFAULT ON ERROR clause. Same NULL input produces different output values in different rows, which is an execution consistency bug.