Re: Unexpected results when using GROUP BY GROUPING SETS and bind variables - Mailing list pgsql-general

From Tom Lane
Subject Re: Unexpected results when using GROUP BY GROUPING SETS and bind variables
Date
Msg-id 67475.1599677153@sss.pgh.pa.us
Whole thread Raw
In response to Re: Unexpected results when using GROUP BY GROUPING SETS and bind variables  (Aner Perez <aner.perez+pgsql-general@gmail.com>)
Responses Re: Unexpected results when using GROUP BY GROUPING SETS and bind variables  (Aner Perez <aner.perez+pgsql-general@gmail.com>)
List pgsql-general
Aner Perez <aner.perez+pgsql-general@gmail.com> writes:
> Or if using indexed path elements in the GROUP BY is the issue and I should
> put the array indexing in a subselect and do the aggregation in the outer
> select.  Like this:

> -- Safer Subselect Version --
> SELECT level1, level2, level3, level4, sum(value)
> FROM (
>     SELECT path[1] as level1, path[2] as level2, path[3] as level3, path[4]
> as level4, value
>     FROM bind_group_by
> ) AS expanded
> GROUP BY GROUPING SETS (
>     (level1, level2, level3, level4),
>     (level1, level2, level3),
>     (level1, level2),
>     (level1),
>     ()
> )
> ORDER BY 1, 2, 3, 4;

Yeah, that one looks a lot safer from here.  There's no question about
which expressions are supposed to match what.  It should end up with
the same plan, too.

            regards, tom lane



pgsql-general by date:

Previous
From: Aner Perez
Date:
Subject: Re: Unexpected results when using GROUP BY GROUPING SETS and bind variables
Next
From: Aner Perez
Date:
Subject: Re: Unexpected results when using GROUP BY GROUPING SETS and bind variables