public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Re: BUG #19401: Inconsistent predicate evaluation with derived table vs direct query involving NULL
Date: Wed, 11 Feb 2026 11:43:41 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
PG Bug reporting form <[email protected]> writes:
> I would like to report a behavior that appears to be incorrect and
> inconsistent in PostgreSQL when the same predicate is evaluated in (1) a
> derived table and (2) a direct query.
> The two queries are logically equivalent, but they return different
> cardinalities.
> CREATE TABLE t0 (c0 TEXT);
> INSERT INTO t0 (c0) VALUES ('4');
> -- result: length 0;
> SELECT ref0 FROM (SELECT (any_value(c0)) AS ref0, ((('j' = NULL) <= (NULL =
> NULL))) AS ref1 FROM t0) AS s WHERE ref1;
> -- result: length 1; (NULL)
> SELECT (any_value(c0)) FROM t0 WHERE (('j' = NULL) <= (NULL = NULL));
These are not "logically equivalent". The first one applies the
WHERE filter above the aggregation, the second one applies it
before the aggregation. An aggregate will produce some value
(typically NULL) even if there are zero input rows, so the second
query gives a single NULL result as-expected. In the first query,
the subselect produces a row (4,NULL) but then the outer WHERE
filters that row away.
regards, tom lane
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: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: BUG #19401: Inconsistent predicate evaluation with derived table vs direct query involving NULL
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox