| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | syzhong16(at)gmail(dot)com |
| Subject: | BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY |
| Date: | 2026-08-15 03:25:40 |
| Message-ID: | 19621-0a480d2dc74e6bd5@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19621
Logged by: Suyang Zhong
Email address: syzhong16(at)gmail(dot)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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alvaro Herrera | 2026-08-15 09:12:00 | Re: Should CUSTER (ANALYZE) work? |
| Previous Message | PG Bug reporting form | 2026-08-15 02:37:43 | BUG #19620: pg_class index corruption caused by statement_timeout during VACUUM FULL |