pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18758: Incorrect query result caused by ROLLUP operation
2+ messages / 2 participants
[nested] [flat]

* BUG #18758: Incorrect query result caused by ROLLUP operation
@ 2024-12-30 16:03 PG Bug reporting form <noreply@postgresql.org>
  2024-12-30 19:11 ` Re: BUG #18758: Incorrect query result caused by ROLLUP operation Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2024-12-30 16:03 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: vectorplanck@gmail.com

The following bug has been logged on the website:

Bug reference:      18758
Logged by:          Pisces Mar.
Email address:      vectorplanck@gmail.com
PostgreSQL version: 17.2
Operating system:   window10
Description:        

create table t1 (c1 char(50));
create table t2 (c1 integer);
select  t1.c1 from t2, t1 group by rollup(t1.c1); -- actual: {null},
expected: {}



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #18758: Incorrect query result caused by ROLLUP operation
  2024-12-30 16:03 BUG #18758: Incorrect query result caused by ROLLUP operation PG Bug reporting form <noreply@postgresql.org>
@ 2024-12-30 19:11 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2024-12-30 19:11 UTC (permalink / raw)
  To: vectorplanck@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> create table t1 (c1 char(50));
> create table t2 (c1 integer);
> select  t1.c1 from t2, t1 group by rollup(t1.c1); -- actual: {null},
> expected: {}

This is the correct result AFAICS.  Per [1], ROLLUP(t1.c1) is a
shorthand for

GROUPING SETS (
    ( t1.c1 ),
    ( )
)

So first you get the output that would correspond to GROUP BY t1.c1,
and with no values of t1.c1 that output is indeed empty.  But then
you get the output for an empty grouping set, which is defined in the
same place as

    An empty grouping set means that all rows are aggregated down to a
    single group (which is output even if no input rows were present),
    as described above for the case of aggregate functions with no
    GROUP BY clause.

So a single row with a null value for t1.c1 is expected, even when
the FROM clause produces no rows.

			regards, tom lane

[1] https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-GROUPING-SETS





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-12-30 19:11 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-30 16:03 BUG #18758: Incorrect query result caused by ROLLUP operation PG Bug reporting form <noreply@postgresql.org>
2024-12-30 19:11 ` Tom Lane <tgl@sss.pgh.pa.us>

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