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 1wva6g-001NRm-3D for pgsql-bugs@arkaria.postgresql.org; Sun, 16 Aug 2026 12:36:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wva6e-00677Y-2g for pgsql-bugs@arkaria.postgresql.org; Sun, 16 Aug 2026 12:36:53 +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 1wv527-003B54-3C for pgsql-bugs@lists.postgresql.org; Sat, 15 Aug 2026 03:26:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wv525-00000000pCJ-3d96 for pgsql-bugs@lists.postgresql.org; Sat, 15 Aug 2026 03:26:08 +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=GsTqbgeyxeDoTBZnpx0f6ktXDTxGy3jVKxdmppwNaJ0=; b=7ZGXwImF7XaqcnndbwEARviQ4g styrPr8gjSEonmtDtwoc5YJC5KsRjOyNR1EXWdXwFfjb8QHUU+kqK+lzRfisJY2kNis0JaYP2Vp6+ ZXWuA4pY8acjMuebNcb6/4pUqA+JI6elpdy0XxdrLyRo5iW//Fo0pZPfyNfiO3/te+imChxBC5Ae0 s1ZSUWcPoMkd0t1P6h/mV4CnOn/+e1Cy/rs9xcOsHVuWMkkpqXy8ZN4/MDnzrygXhbGaJE5brijVf geHeUJt0qqqNSSLAMRRKaX/uRwCCboawTJRvyCfK8dfVjTElEToZyHwEHtqGLxhcbqp85bHuQDFzi VC7oB4yQ==; 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 1wv524-0025gO-38 for pgsql-bugs@lists.postgresql.org; Sat, 15 Aug 2026 03:26:05 +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 1wv523-00000005j9B-2mSr for pgsql-bugs@lists.postgresql.org; Sat, 15 Aug 2026 03:26:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: syzhong16@gmail.com Reply-To: syzhong16@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sat, 15 Aug 2026 03:25:40 +0000 Message-ID: <19621-0a480d2dc74e6bd5@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: 19621 Logged by: Suyang Zhong Email address: syzhong16@gmail.com PostgreSQL version: 19beta3 Operating system: Ubuntu 22.04 Description: =20 Consider the following test case: ```sql CREATE TABLE t0(x text); INSERT INTO t0 VALUES ('{}'), (NULL); CREATE VIEW v0 AS SELECT x, json_value(x, '$.a' RETURNING int DEFAULT 42 ON EMPTY) AS jv FROM t0; SELECT x IS NULL AS is_null, jv FROM v0; -- f | 42 -- t | 42 SELECT jv FROM v0 WHERE x IS NULL; -- NULL ``` The second query selects exactly the row the first query shows as `t | 42`, yet returns NULL for its `jv`. A further reduction shows that the result depends on the input row order. ```sql SELECT json_value(x, '$.a' RETURNING int DEFAULT 42 ON EMPTY) FROM (VALUES ('{}'), (NULL)) v(x); -- 42 -- 42 SELECT json_value(x, '$.a' RETURNING int DEFAULT 42 ON EMPTY) FROM (VALUES (NULL), ('{}')) v(x); -- NULL -- 42 ``` Reproduced on 20devel, and on 17.11, 18.1, 18.4, and 19beta3; on 17rc1 only the `ON ERROR` variants misbehave.