-
Notifications
You must be signed in to change notification settings - Fork 990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A small note on the order of cube result #3179
Comments
Thanks for investigating that. BTW. there is a great webtool www.sqlfiddle.com |
Thanks for the tip about sqlfiddle Jan - will check it out. I also want to take the opportunity to thank all |
Line 32 in e2a95fb
has to be modified to produce expected order, probably each /times arguments. Eventually we can move to slower (but easier to follow) way to generate list of character strings that is passed to groupingsets .data for sqlfiddle: d[, sprintf("insert into t1 values (%s,%s,%s,%s);", a, b, c, val), 1:nrow(d)
][, cat(paste(c("create table t1 (a int, b int, c int, val int);", V1), collapse="\n"))
] -> nul SELECT GROUPING(a, b, c), a, b, c, sum(val) FROM t1 GROUP BY cube (a, b, c); |
I pushed fix, while it fixes the order of |
In the Description in
?cube
, we find that [cube
]Then, the Value section is rather vague:
...but References are provided to PostgreSQL 7.2.4. GROUPING SETS, CUBE, and ROLLUP.
There we find that:
is equivalent to
It seems like the first grouping variable varies slowest, and the last variable varies fastest. Disclaimer: I don't have access to PostgreSQL, so I can't confirm that this actually reflects the final output ;)
In
cube
, it is the other way around: the last grouping variable inby
varies slowest, and the first fastest, like:I don't claim that PostgreSQL is "right", but given that no explicit Value section is provided in
?cube
, and that the help text instead refers to PostgreSQL docs, the order ofcube
output may be considered inconsistent (but again, note my disclaimer above). In addition, I find the PostgreSQL ordering more intuitive, a matter of taste perhaps.An example to illustrate the order of
cube
:Update
When I added an
id
, it's obvious that the counter is in fact based on the PostgreSQL order, which in the current output order becomes non-consecutive. Somewhat odd. It seems to me that the output rather could have the PostgreSQL order right away.The text was updated successfully, but these errors were encountered: