pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: syzhong16@gmail.com
Subject: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY
Date: Sat, 15 Aug 2026 03:25:40 +0000
Message-ID: <19621-0a480d2dc74e6bd5@postgresql.org> (raw)

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:        

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.








view thread (14+ messages)  latest in thread

Message-ID: <19621-0a480d2dc74e6bd5@postgresql.org>
Permalink:  ../19621-0a480d2dc74e6bd5@postgresql.org/
Also on:    postgresql.org/message-id/19621-0a480d2dc74e6bd5@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, syzhong16@gmail.com
  Subject: Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY
  In-Reply-To: <19621-0a480d2dc74e6bd5@postgresql.org>
  References: <19621-0a480d2dc74e6bd5@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox