[sc34wg3] TMQL: Grammar "order by clause"

Robert Barta rho at devc.at
Thu Mar 5 10:28:51 EST 2009

On Sun, Nov 30, 2008 at 09:31:23PM +0100, Lars Heuer wrote:
> The productions [51] "select expression" and [52] "flwr expression"
> contain an optional "order by" clause. This is specified as follows:
>     order-by-clause ::= 'order' 'by' value-expression (',' value-expression)*
> There is no possibility to specify the ordering (ascending / descending).

Correct, here the draft is _definitely_ broken.

> On the other hand, [24] "tuple expression" provides the "asc" / "desc"
> keywords but requires parenthesis:
>     tuple-expression ::= '(' value-expression ('asc'|'desc')? (',' value-expression)* ')'
> Are the parentheses optional iff a tuple expression contains just one
> value expression or is the order-by clause wrong?

You also correctly point into the direction I am thinking how this
should be fixed.

The shortest way (i.e. reusing existing things) would be to say

   order-by-clause ::= 'order' 'by' tuple-expression                ((A))

but then - as you write - one always has to use ():

  select $p / name
  order by ( $p / age desc, $p / shoesize asc )

AFAIR, the () in tuple expressions cannot be (simply) dropped, as this
makes a big KABOOOM! somewhere else (ambiguous, tried that and failed

These parentheses are not that bad, actually, as they help to provide
maybe more pointed error messages.

If all that is not pleasing to the beardy SQL hacker, then we
certainly can add asc/desc 'manually':

  order-by-clause ::= 'order' 'by' < value-expression [ 'asc'|'desc' ] >   ((B))

I personally would favour slightly ((A)), so I assume everyone else is
favouring ((B))?

BTW: Should we not make the 'by' optional?


More information about the sc34wg3 mailing list