mirror of
https://github.com/allankoechke/turso.git
synced 2026-12-02 09:49:09 +00:00
When an ORDER BY or LIMIT clause appears before a compound operator, as in `SELECT 1 ORDER BY 1 UNION SELECT 2`, the parser stopped the compound-select loop at the clause and then failed on the leftover operator token with a generic `near "UNION": syntax error`. SQLite instead reports `ORDER BY clause should come after UNION not before`, so error-message compatibility tests failed. After parsing a select's ORDER BY and LIMIT clauses, peek at the next token: a compound operator there can only mean one of those clauses cut the compound-select loop short, so report SQLite's message instead. As in SQLite, ORDER BY takes precedence over LIMIT when both are present and UNION ALL is named in full. This removed the last failures in the upstream conformance files selectE.test and subquery2.test, so promote both from "fail" to "pass" in sqlite/conformance/upstream/all.test. Tests: sqlite-sqltests/compound-select-order-by-before-operator-error.sqltest, tclsh sqlite/conformance/upstream/all.test (selectE and subquery2 now blessed), cargo test in sqlite/parser, full sqltest corpus via make -C sqlite/conformance run-rust. Fixes #8201
TODO