Skip to content

fix(parser): parse IS/ISNULL/NOTNULL with lower precedence than comparison - #8668

Closed
ansh-rohilla wants to merge 1 commit into
tobymao:mainfrom
ansh-rohilla:fix/postgres-operator-precedence-8661
Closed

ansh-rohilla wants to merge 1 commit into
tobymao:mainfrom
ansh-rohilla:fix/postgres-operator-precedence-8661

Conversation

@ansh-rohilla

Copy link
Copy Markdown
Contributor

In standard SQL and PostgreSQL operator precedence, comparison operators (=, !=, <>, <, >, <=, >=) have higher precedence than IS, IS NOT, ISNULL, and NOTNULL.

Previously in SQLGlot, IS was registered in RANGE_PARSERS under _parse_range(), which sits underneath _parse_comparison() and _parse_equality(). Consequently, in an expression like t.a = t.b IS NULL, t.b IS NULL was evaluated first as the right-hand operand of =.

This PR introduces _parse_is_predicate() in the parser between conjunctions (AND) and equality/comparison (_parse_equality()), and removes IS from RANGE_PARSERS.

Closes #8661

@ansh-rohilla
ansh-rohilla force-pushed the fix/postgres-operator-precedence-8661 branch from d26b6cb to bf601af Compare October 17, 2026 12:57
@georgesittas

Copy link
Copy Markdown
Collaborator

Thanks, but the core team will take a look at this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parser (postgres): wrong operator precedence

2 participants