Patrick,

> This query does not work:
> sparql select ?g count(?g) where {graph ?g {?s ?p ?o}} order by
count(?g)
> This is ok:
> sparql select ?g count(?g) where {graph ?g {?s ?p ?o}} order by
(count(?g))

That is correct. Sorting list consists of variables and expressions with
direction indicators, i.e. the following clauses are all legal:
order by ?var1 ?var2
order by asc (2+2)
order by desc (count(?g))
order by (count(?g))

The bottom one is valid because according to SPARQL grammar ASC keyword
is optional. Nevertheless parentheses around expression are required as
soon as the expression is not a single variable. This is because, say, 
order by abc:def (?g)
is ambiguous, it can be treated as 
"order by abc:def then order by by (?g)"
or as
"order by result of calling function abc:def with argument ?g".
Similarly, in list of result set expressions one can write
select ?var1 ?var2 ...
select (2+2) ...
but not
select abc:def (?g) ...

As exception, aggregate functions can be used in select without
parentheses around them. That was bad idea but now it seems that this
bad practice should be extended to ORDER BY lists as well because the
difference is misleading. Other misleading thing to be fixed is that
commas are now allowed between expressions after SELECT but not allowed
after ORDER BY.

Best Regards,
Ivan Mikhailov
OpenLink Software



Reply via email to