-
Notifications
You must be signed in to change notification settings - Fork 612
Allow parentheses in GROUP BY #390
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the contribution -- sorry for the delay in response @yuval-illumex
So I was playing around with postgres and there is a difference between col1, col2
and (col1, col2)
. Specifically, I think (col1, col2)
is treated as some tuple type.
I think this PR effectively strips off the parenthesis
alamb=# select (t1_id, t1_name), count(*) from t1 group by (t1_id, t1_name);
row | count
--------+-------
(44,d) | 1
(77,e) | 1
(11,a) | 1
(22,b) | 1
(33,c) | 1
(5 rows)
alamb=# select t1_id, t1_name, count(*) from t1 group by t1_id, t1_name;
t1_id | t1_name | count
-------+---------+-------
44 | d | 1
77 | e | 1
11 | a | 1
22 | b | 1
33 | c | 1
(5 rows)
Turns out that mysql just rejects this syntax
mysql> select (t1_id, t1_name), count(*) from t1 group by (t1_id, t1_name);
ERROR 1241 (21000): Operand should contain 1 column(s)
I didn't catch it quite in time, but the same thing is true for distinct: #391
I don't have a trino
installation around to test -- what does trino do with the syntax above?
Thanks @alamb The following syntax works in Trino: This is the default schemas and tables coming with tirno, so you can tun Trino with docker to play with using this query. I'm more worried about GroupBy rather then Select - I think the parentheses are more common in GroupBy (and Distinct) |
Thanks @yuval-illumex -- it looks to me like in this case too Trino is treating |
@yuval-illumex can you please look into parsing I think you may be able to |
@alamb parse_tuple do works, but I could use some help. It parses expressions, and I'm not sure how to identify when it should be an expression and when should it be a tuple. as the function must return an expression. |
Looking into it |
@yuval-illumex this is what I had in mind (it should cover all paren cases): #414 |
Probably not needed after #414 |
In TrinoDB, GROUP BY Can have parentheses with multiple values.
Example Query: