duckdb-web
duckdb-web copied to clipboard
Syntax diagram for ORDER BY and LIMIT clause suggests there can be no LIMIT without ORDER BY
On this page of the documentation:
https://duckdb.org/docs/sql/statements/select#order-by-and-limit-clauses
we see the syntax diagram for the ORDER BY and LIMIT clause
The diagram appears to imply that a LIMIT clause must be preceded by an ORDER BY clause. This is not the case in reality and certainly in data exploration use cases LIMIT is used all the time without ORDER BY clause.
I suppose that in a serious query, applying LIMIT without ORDER BY is semantically wrong or at least not a good practice, because the result may be indeterministic because we cannot (should not) reply on any specific order. I suppose the formal syntax diagram might express that concern by suggesting LIMIT must be preceded by an ORDER BY clause.
Still it would be good if there would be some clarification at this point. Personally I would prefer it if the documentation treated LIMIT as a separate clause, and some text was added there to explain that using LIMIT without ORDER BY can lead to unexpected results.