Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY - Mailing list pgsql-bugs

From Andrey Rachitskiy
Subject Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY
Date
Msg-id CAB8bMiua3O8ZA1YHzQQYNLeDg+Pyom-XoiDx4_Z_QoA8WCu7Rw@mail.gmail.com
Whole thread
In response to Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY  (jian he <jian.universality@gmail.com>)
List pgsql-bugs


сб, 26 сент. 2026 г. в 21:29, jian he <jian.universality@gmail.com>:
On Fri, Sep 4, 2026 at 6:38 PM Andrey Rachitskiy <pl0h0yp1@gmail.com> wrote:
>
> Attached is v2 of the patch.
>
> --
> Regards,
> Rachitskiy Andrey


+ EEO_CASE(EEOP_JSONEXPR_RESET)
+ {
+ ExecEvalJsonExprReset(state, op);
+
+ EEO_NEXT();
+ }
+

--- a/src/include/executor/execExpr.h
+++ b/src/include/executor/execExpr.h
@@ -265,6 +265,7 @@ typedef enum ExprEvalOp
  EEOP_XMLEXPR,
  EEOP_JSON_CONSTRUCTOR,
  EEOP_IS_JSON,
+ EEOP_JSONEXPR_RESET,
  EEOP_JSONEXPR_PATH,
  EEOP_JSONEXPR_COERCION,
  EEOP_JSONEXPR_COERCION_FINISH,

This seems unnecessary.
In EEOP_JSONEXPR_PATH, we can
if document or jsonpath is NULL, we can just go to jump_end (return
NULL) or jump_eval_coercion (NULL need coerce to constrainted domain),
no need to worry about ON ERROR, ON EMPTY.

What do you think of the attachment?



--
jian
https://www.enterprisedb.com/

Hi, Jian!

Thanks for posting this alternative.

I considered the same shape earlier: keep the empty/error reset in EEOP_JSONEXPR_PATH and stop skipping that step on SQL NULL. Your version is simpler than adding EEOP_JSONEXPR_RESET. No new opcode, and no JIT or back-branch ABI churn.

The commit message still described a RESET opcode that the diff does not add. I adjusted the subject and body to match what the patch actually does (retarget JUMP_IF_NULL at PATH, drop the CONST NULL pad, handle NULL inside ExecEvalJsonExprPath).

Either approach fixes the reported cases. I am fine with whichever version a committer prefers.


Attachment

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #19725: PostgreSQL 18.6: pg_restore read failure with io_uring, not observed with worker
Next
From: Peter Geoghegan
Date:
Subject: Re: BUG #19686: Rolling back SET TABLESPACE + INSERT leads to index corruption