You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Zhen Chen (Jira)" <ji...@apache.org> on 2025/12/17 00:50:00 UTC

[jira] [Resolved] (CALCITE-5347) Add 'SELECT ... BY', a syntax extension that is shorthand for GROUP BY and ORDER BY

     [ https://issues.apache.org/jira/browse/CALCITE-5347?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Zhen Chen resolved CALCITE-5347.
--------------------------------
    Fix Version/s: 1.42.0
         Assignee: Zhen Chen
       Resolution: Fixed

Fixed in [{{55aec64}}|https://github.com/apache/calcite/commit/55aec64a33d2b6d69043b522df9393268721a5a2]

Thanks for review [~mbudiu] [~julianhyde] 

Please feel free to contact me if any further processing is required.

> Add 'SELECT ... BY', a syntax extension that is shorthand for GROUP BY and ORDER BY
> -----------------------------------------------------------------------------------
>
>                 Key: CALCITE-5347
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5347
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Assignee: Zhen Chen
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.42.0
>
>
> Many people have observed that SQL query syntax is verbose if you want to eliminate duplicates and sort. Business intelligence tools often have query languages that eliminate duplicates and sort by default; we cannot do that in the SQL {{SELECT}} expression, because that would break compatibility. But we propose the following variation of {{SELECT}} that is distinguishable from regular {{SELECT}} (i.e. queries that use it would be invalid in ordinary SQL) but concise and intuitive.
> We propose
> {code:sql}
> SELECT a BY b
> FROM t {code}
> as syntactic sugar for
> {code:sql}
> SELECT b, a
> FROM t
> GROUP BY b
> ORDER BY b{code}
> In the above, {{a}} and {{b}} may be lists of columns, the columns may include aliases, and the columns in {{b}} may include sort-key modifiers such as {{DESC}} and {{NULLS LAST}}.
> For example,
> {code:sql}
> SELECT e.ename, e.empno BY d.dname AS dept DESC, e.job AS title
> FROM Emp AS e
>   JOIN Dept AS d ON e.deptno = d.deptno
> WHERE d.loc = 'CHICAGO'{code}
> is shorthand for
> {code:sql}
> SELECT d.dname AS dept, e.job AS title,
>   e.ename, e.empno
> FROM Emp AS e
>   JOIN Dept AS d ON e.deptno = d.deptno
> WHERE d.loc = 'CHICAGO'
> GROUP BY d.dname, e.job
> ORDER BY d.dname DESC, e.job {code}
>  
> This feature was inspired by [Shakti|https://shakti.com/], a SQL-like language by Arthur Whitney, author of the k language.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)