Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY

From: Manu <manuelreyesbravo(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>, Amit Langote <amitlangote09(at)gmail(dot)com>, syzhong16(at)gmail(dot)com
Subject: Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY
Date: 2026-09-23 20:12:30
Message-ID: 179019435072.698927.9020965732916209558@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Andrey,

I tested v2 on master, REL_18_STABLE and REL_17_STABLE, together with
Srinath's fix for #19695 [1], which touches the same function. Both
apply cleanly on all three branches, build without warnings, and the
main regression suite passes. The reported cases now give the right
answer on the three branches:

- #19621: json_value(x, '$.a' RETURNING int DEFAULT 42 ON EMPTY) over
'{}' then NULL returns 42, NULL (it was 42, 42)
- #19654: json_exists(j, 'strict $.a' FALSE ON ERROR) over '{}' then
NULL returns false, NULL (it was false, false)

I could not exercise the llvmjit_expr.c part: this machine has no LLVM
build.

One thing for the back-patch. EEOP_JSONEXPR_RESET is inserted before
EEOP_JSONEXPR_PATH, so every opcode from there to EEOP_LAST changes its
value: 24 of them on REL_17_STABLE and 25 on REL_18_STABLE. On master
that is fine, but the back branches are under the buildfarm's ABI
compliance check (.abi-compliance-history), and anything built against
a minor release that uses those values would be off by one after the
update. Putting the new opcode just before EEOP_LAST in the
back-branch versions, with the dispatch table and llvmjit_expr.c
following the same order, would leave the existing values alone.

If you post back-branch versions, I will rerun the same checks on
them.

[1]
https://postgr.es/m/CAFC+b6p8Oo3_pLXPa=DVXx1XDQJ09b2W3U3WKPtkQYyh0z0z-A@mail.gmail.com

Regards,
Manu

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Manu 2026-09-23 20:12:34 Re: BUG #19695: JSON_VALUE ... RETURNING jsonb returns NULL for later evaluation once one evaluation returns NULL
Previous Message Manu 2026-09-23 19:50:31 Re: BUG #19641: Unexpected results on an SP-GiST indexed column with a non-deterministic collation