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

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: runyuan(at)berkeley(dot)edu, pgsql-bugs(at)lists(dot)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: BUG #19046: Incorrect result when using json_array() with column reference in subquery combined with RIGHT JOIN
Date: 2025-09-10 13:29:41
Message-ID: CAMbWs4_ijQEsfJPOvexRn0oweMoGZetOfmEZwRKrw6t_e0YY+g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Sep 10, 2025 at 9:31 PM Tender Wang <tndrwang(at)gmail(dot)com> wrote:
>> PG Bug reporting form <noreply(at)postgresql(dot)org> 于2025年9月10日周三 18:22写道:
>>> SELECT sub.c FROM
>>> (SELECT json_array(3, 2, t.c) AS c FROM t) AS sub
>>> RIGHT JOIN t ON FALSE;

> diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
> index 6f0b338d2cd..5ef364b7f7c 100644
> --- a/src/backend/optimizer/util/clauses.c
> +++ b/src/backend/optimizer/util/clauses.c
> @@ -1115,6 +1115,8 @@ contain_nonstrict_functions_walker(Node *node, void *context)
> return true;
> if (IsA(node, BooleanTest))
> return true;
> + if (IsA(node, JsonConstructorExpr))
> + return true;
>
> I added the above codes, then the query returned the correct result.
> I didn't dig more the details. Any thought?

Yeah, JsonConstructorExpr should not be treated as a non-strict
construct. This fix looks correct to me.

I'm wondering if this is the only case we've overlooked. How about
other Json-related expressions?

- Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-09-10 20:18:05 Re: BUG #19040: Memory leak in hashed subplan node due to missing hashtempcxt reset
Previous Message Tender Wang 2025-09-10 12:30:59 Re: BUG #19046: Incorrect result when using json_array() with column reference in subquery combined with RIGHT JOIN