retrieve grouping sets/rollup rows

Started by Tom Smithabout 10 years ago8 messagesgeneral
Jump to latest
#1Tom Smith
tomsmith1989sk@gmail.com

Hello:

With JDBC, how can I tell which row is for which grouping sets or rollup
using result sets

Thanks

#2James Keener
jim@jimkeener.com
In reply to: Tom Smith (#1)
Re: retrieve grouping sets/rollup rows

Do you want to know if a row is from the (a,b) or (c,d) group? All rows
will contain (a,b,c,d) but (a,b) will be NULL for the (c,d) grouping
sets, and vice-versa.

Jim

On 03/13/2016 09:45 PM, Tom Smith wrote:

Hello:

With JDBC, how can I tell which row is for which grouping sets or rollup
using result sets

Thanks

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Tom Smith
tomsmith1989sk@gmail.com
In reply to: James Keener (#2)
Re: retrieve grouping sets/rollup rows

It would help if the resultset has some param to mark which is which with
the grouping sets index.
for example, the results for (a,b,c,d) would be marked as for index =0,
(b,c,d) would be index=1

On Sun, Mar 13, 2016 at 9:52 PM, James Keener <jim@jimkeener.com> wrote:

Show quoted text

Do you want to know if a row is from the (a,b) or (c,d) group? All rows
will contain (a,b,c,d) but (a,b) will be NULL for the (c,d) grouping
sets, and vice-versa.

Jim

On 03/13/2016 09:45 PM, Tom Smith wrote:

Hello:

With JDBC, how can I tell which row is for which grouping sets or rollup
using result sets

Thanks

#4James Keener
jim@jimkeener.com
In reply to: Tom Smith (#3)
Re: retrieve grouping sets/rollup rows

Why? You're already provided with this information: NULL fields are not
being used in the grouping set for the row. Moreover, it would seem to
be an implementation- and run-time- dependent value, as there is no
reason group by grouping set (a,b), (c,d) couldn't be executed in
written order, or (c,d) first depending on a lot of things.

Forcing the implementation to conform to a certain way of doing things
is asking for someone to ask why a certain optimization isn't being
performed later on.

My $0.02.

Jim

On 03/13/2016 10:07 PM, Tom Smith wrote:

It would help if the resultset has some param to mark which is which
with the grouping sets index.
for example, the results for (a,b,c,d) would be marked as for index =0,
(b,c,d) would be index=1

On Sun, Mar 13, 2016 at 9:52 PM, James Keener <jim@jimkeener.com
<mailto:jim@jimkeener.com>> wrote:

Do you want to know if a row is from the (a,b) or (c,d) group? All rows
will contain (a,b,c,d) but (a,b) will be NULL for the (c,d) grouping
sets, and vice-versa.

Jim

On 03/13/2016 09:45 PM, Tom Smith wrote:

Hello:

With JDBC, how can I tell which row is for which grouping sets or

rollup

using result sets

Thanks

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#5James Keener
jim@jimkeener.com
In reply to: James Keener (#4)
Re: retrieve grouping sets/rollup rows

It just dawned on me that you may note have meant having them in a
specific sequence in the result set. Even still, I think it's much more
clear being explicit with what rows are included and which aren't.

Jim

On 03/13/2016 10:12 PM, James Keener wrote:

Why? You're already provided with this information: NULL fields are not
being used in the grouping set for the row. Moreover, it would seem to
be an implementation- and run-time- dependent value, as there is no
reason group by grouping set (a,b), (c,d) couldn't be executed in
written order, or (c,d) first depending on a lot of things.

Forcing the implementation to conform to a certain way of doing things
is asking for someone to ask why a certain optimization isn't being
performed later on.

My $0.02.

Jim

On 03/13/2016 10:07 PM, Tom Smith wrote:

It would help if the resultset has some param to mark which is which
with the grouping sets index.
for example, the results for (a,b,c,d) would be marked as for index =0,
(b,c,d) would be index=1

On Sun, Mar 13, 2016 at 9:52 PM, James Keener <jim@jimkeener.com
<mailto:jim@jimkeener.com>> wrote:

Do you want to know if a row is from the (a,b) or (c,d) group? All rows
will contain (a,b,c,d) but (a,b) will be NULL for the (c,d) grouping
sets, and vice-versa.

Jim

On 03/13/2016 09:45 PM, Tom Smith wrote:

Hello:

With JDBC, how can I tell which row is for which grouping sets or

rollup

using result sets

Thanks

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: James Keener (#5)
Re: retrieve grouping sets/rollup rows

On 03/13/2016 10:07 PM, Tom Smith wrote:

It would help if the resultset has some param to mark which is which
with the grouping sets index.

I think you're looking for the GROUPING() function. See
http://www.postgresql.org/docs/9.5/static/functions-aggregate.html

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#7James Keener
jim@jimkeener.com
In reply to: Tom Lane (#6)
Re: retrieve grouping sets/rollup rows

/me has learned something new!

Thanks!

On 03/13/2016 10:44 PM, Tom Lane wrote:

On 03/13/2016 10:07 PM, Tom Smith wrote:

It would help if the resultset has some param to mark which is which
with the grouping sets index.

I think you're looking for the GROUPING() function. See
http://www.postgresql.org/docs/9.5/static/functions-aggregate.html

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#8Tom Smith
tomsmith1989sk@gmail.com
In reply to: Tom Lane (#6)
Re: retrieve grouping sets/rollup rows

exactly what I am looking for. very nice. Thx

On Sun, Mar 13, 2016 at 10:44 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Show quoted text

On 03/13/2016 10:07 PM, Tom Smith wrote:

It would help if the resultset has some param to mark which is which
with the grouping sets index.

I think you're looking for the GROUPING() function. See
http://www.postgresql.org/docs/9.5/static/functions-aggregate.html

regards, tom lane