parsing bug with intersect, dialect: postgres
Open
@treysp is already working on this.
Since Sep 18, 2026.
- Dominant language
- Python
- Stars
- 9.6k
- Forks
- 1.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 90
Description
postgres: there is a bug while parsing a chain of union/intersect
postgres doc (18.6) state:
without parentheses,
UNION and EXCEPT associate left-to-right, but INTERSECT binds more tightly than those two
operators. Thus
query1 UNION query2 INTERSECT query3
means
query1 UNION (query2 INTERSECT query3)
from sqlglot import parse_one
select = """select 1 union select 2 intersect select 3"""
parse_one(select, dialect= "postgres")
show -> (query1 UNION query2) INTERSECT query3
instead of -> query1 UNION (query2 INTERSECT query3)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.