tobymao / tobymao/sqlglot

parsing bug with intersect, dialect: postgres

Open
#8,390 1 comment 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.