Re: BUG #19046: Incorrect result when using json_array() with column reference in subquery combined with RIGHT JOIN

Tender Wang <tndrwang@gmail.com>

From: Tender Wang <tndrwang@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Richard Guo <guofenglinux@gmail.com>, runyuan@berkeley.edu, pgsql-bugs@lists.postgresql.org
Date: 2025-09-12T00:57:27Z
Lists: pgsql-bugs
Tom Lane <tgl@sss.pgh.pa.us> 于2025年9月11日周四 11:16写道:

> Richard Guo <guofenglinux@gmail.com> writes:
> > I tested JsonExpr, which is the representation of json_value,
> > json_query and json_exists.  It seems that they could not produce
> > non-NULL output with a NULL input.  So we are good on that front.
>
> Seems like we ought to actually look at the relevant code, not
> try to test our way to an understanding of it.
>
>


I read the  ExecInitJsonExpr() code, it has:

/*
* Evaluate formatted_expr storing the result into
* jsestate->formatted_expr.
*/
ExecInitExprRec((Expr *) jsexpr->formatted_expr, state,
&jsestate->formatted_expr.value,
&jsestate->formatted_expr.isnull);

/* JUMP to return NULL if formatted_expr evaluates to NULL */
jumps_return_null = lappend_int(jumps_return_null, state->steps_len);
scratch->opcode = EEOP_JUMP_IF_NULL;
scratch->resnull = &jsestate->formatted_expr.isnull;
scratch->d.jump.jumpdone = -1; /* set below */
ExprEvalPushStep(state, scratch);

The above codes say that it will directly return null if formatted_expr
evaluates to NULL.

-- 
Thanks,
Tender Wang