I am working on a SQL grammar similar (at a high level) to BigQuery, which has the following
However, I believe this grammar may be ambiguous (also pointed out in the answer from here:
You can make the set_operator
right-associative like so:
query_statement
: query_expr # simplequery
| <assoc=right> query_statement set_operator query_statement # setQuery
;
This has no effect on which SELECT
the LIMIT
binds to.
Off hand, I'm not sure how you would get
SELECT 1 UNION SELECT 1 LIMIT 1
interpreted as:
(SELECT 1 UNION (SELECT 1) LIMIT 1)
(it also seems as though it would be a most unintuitive interpretation of the input, but that's just my opinion)