pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: runyuan@berkeley.edu
Subject: BUG #19046: Incorrect result when using json_array() with column reference in subquery combined with RIGHT JOIN
Date: Wed, 10 Sep 2025 07:14:35 +0000
Message-ID: <19046-765b6602b0a8cfdf@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      19046
Logged by:          Runyuan He
Email address:      runyuan@berkeley.edu
PostgreSQL version: 18rc1
Operating system:   Linux (x86)
Description:        

Bug Description:
When using json_array() function with a column reference from table t inside
a subquery, and then performing a RIGHT JOIN with condition FALSE, the
result incorrectly returns [3, 2] instead of the expected NULL value.

Reproducible Example:
CREATE TABLE t(c INT);
INSERT INTO t VALUES (1);

SELECT sub.c FROM
(SELECT json_array(3, 2, t.c) AS c FROM t) AS sub
RIGHT JOIN t ON FALSE;
-- PostgreSQL 16.x: Returns NULL (CORRECT)
-- PostgreSQL 17.6, 17.rc1: Returns [3, 2] (INCORRECT)
-- PostgreSQL 18rc1: Returns [3, 2] (INCORRECT)

SELECT sub.c FROM
(SELECT json_array(3, 2, t.c) AS c FROM t) AS sub;
-- Returns [3, 2, 1] (CORRECT)

SELECT sub.c FROM
(SELECT json_array(3, 2, 1) AS c FROM t) AS sub
RIGHT JOIN t ON FALSE;
-- Returns Null (CORRECT)



view thread (11+ messages)  latest in thread

Message-ID: <19046-765b6602b0a8cfdf@postgresql.org>
Permalink:  ../19046-765b6602b0a8cfdf@postgresql.org/
Also on:    postgresql.org/message-id/19046-765b6602b0a8cfdf@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, runyuan@berkeley.edu
  Subject: Re: BUG #19046: Incorrect result when using json_array() with column reference in subquery combined with RIGHT JOIN
  In-Reply-To: <19046-765b6602b0a8cfdf@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox