pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: vectorplanck@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18758: Incorrect query result caused by ROLLUP operation
Date: Mon, 30 Dec 2024 14:11:06 -0500
Message-ID: <3879324.1735585866@sss.pgh.pa.us> (raw)
In-Reply-To: <18758-7bbeea9719044a29@postgresql.org>
References: <18758-7bbeea9719044a29@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





view thread (2+ messages)

Message-ID: <3879324.1735585866@sss.pgh.pa.us>
Permalink:  ../3879324.1735585866@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3879324.1735585866@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, vectorplanck@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18758: Incorrect query result caused by ROLLUP operation
  In-Reply-To: <3879324.1735585866@sss.pgh.pa.us>

* 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