Re: BUG #19969: Result inconsistency with scale() over an INTERSECT subquery

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: enjolras_k(at)outlook(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19969: Result inconsistency with scale() over an INTERSECT subquery
Date: 2026-12-02 15:45:18
Message-ID: 1913051.1796226318@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> On PostgreSQL 19.0, I observed different results for an
> INTERSECT query and its explicitly materialized version.
> I expected the two queries to return the same count, but
> they return 0 and 1 respectively.

> CREATE TABLE a(v numeric);
> CREATE TABLE b(v numeric);
> INSERT INTO a VALUES (1);
> INSERT INTO b VALUES (1.0);

> SELECT count(*)
> FROM (
> SELECT v FROM a
> INTERSECT
> SELECT v FROM b
> ) q
> WHERE scale(v) = 0;
> -- Actual: 0

[ shrug... ] This query is ill-defined. Numeric "1" and "1.0" are
equal, so they'll be merged into one row by INTERSECT, and which
one you'll get as the representative output is unspecified. But
the "scale(v)" condition can tell them apart, therefore the
query results are likewise unspecified.

In the particular case at hand, things are complicated by whether or
not the planner pushes the scale(v) condition below the INTERSECT
... but even if it did not do that, the results would be unspecified
and could vary based on any number of things.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavan 2026-12-02 15:49:33 Re: BUG #19953: pg_stat_io exposes impossible rows for io worker backends
Previous Message jian he 2026-12-02 15:43:34 Re: BUG #19872: JSON_TABLE: an UNUSED PASSING argument's COLLATE leaks into the output columns (wrong results, persi