News for hackers. Stuff that matters.
Re:Seldomly Used SQL: The Bool Aggregate Functions by cjauvin on Thursday May 05, 2016 @02:54PM (#11638804)
It's actually the first time I'm seeing the `group by 1, 2` syntax.. is that Postgres-specific?
Re:Seldomly Used SQL: The Bool Aggregate Functions by nickpeterson on Thursday May 05, 2016 @04:18PM (#11639347)
MSSQL doesn't support it, but does support the ORDER BY 1,2 syntax that is very similar.

I don't believe GROUP BY n1,n2.. should be allowed, because it inverts the flow of control of the query. If you think about it, you're telling SQL to group by a column you haven't specified yet, using the order it appears in the SELECT clause. Someone could edit the query and add a new column at the front of the select list and completely change the meaning of the query. I think the ORDER BY clause has similar issues, but at least that occurs after the SELECT happens.

tl;dr I shouldn't have to look at the ordering of the select to understand what has been grouped by.

Order of SQL operations for the uninitiated, this explains why you can't, for instance, reference a column alias defined in a SELECT clause in the WHERE clause.

  6 SELECT
  1 FROM
  2 JOIN
  3 WHERE
  4 GROUP BY
  5 HAVING
  7 ORDER BY
Re:Seldomly Used SQL: The Bool Aggregate Functions by coredog64 on Thursday May 05, 2016 @03:16PM (#11638946)
"group by 1,2" is for lazy people who never have to support an application in production. It tells the database to group by the columns in the order that they come back in the result and is supported by most engines.
Re:Seldomly Used SQL: The Bool Aggregate Functions by ak4g on Thursday May 05, 2016 @11:57PM (#11641589)
Much like SELECT * or JOIN foo USING(bar), it's the kind of thing that greatly speeds up interactive queries, but shouldn't ever end up in source control.
Re:Seldomly Used SQL: The Bool Aggregate Functions by JoeCamel on Friday May 06, 2016 @02:12AM (#11642039)
Why "JOIN foo USING (bar)" shouldn't be used?
Re:Seldomly Used SQL: The Bool Aggregate Functions by ak4g on Friday May 06, 2016 @08:27PM (#11647716)
Because with USING, you're precluded from using the full table.column identifier in your JOIN condition. Without that, a future ALTER TABLE that adds another "bar" column to an existing table in the FROM-list will cause a previously-working query to break.

https://gist.github.com/AdamG/1128b86fdafca1e53a4bd5253a6882...

Re:Seldomly Used SQL: The Bool Aggregate Functions by nimish on Thursday May 05, 2016 @05:51PM (#11639910)
it'd be bad style to use it for saved queries but for experimentation it's great
Re:Seldomly Used SQL: The Bool Aggregate Functions by atwebb on Thursday May 05, 2016 @03:09PM (#11638895)
Don't believe you can do it in MSSQL, though an order by outer reference would work.