PostgreSQL: support right-deep join chains (deferred ON clauses)#3
Merged
moshap-firebolt merged 2 commits intoJun 15, 2026
Merged
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 64210ff. Configure here.
PostgreSQL accepts join chains where ON clauses are deferred to the end, e.g.:
t0 JOIN t1 JOIN t2 ON c1 ON c2
This is equivalent to t0 JOIN (t1 JOIN t2 ON c1) ON c2 per the SQL standard's
right-associative interpretation when parentheses are absent. The parser already
handles this for Snowflake via supports_left_associative_joins_without_parens();
PostgreSQL was missing the override, causing a parse error on any right-deep chain
of depth >= 3.
Also filed upstream: apache#2377
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…pache#2355) Cherry-picked from upstream apache/datafusion-sqlparser-rs@d0c081e
64210ff to
6be2947
Compare
5948ede
into
firebolt/v0.62.0-pathological
2 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PostgreSQL accepts join chains where ON clauses are deferred to the end, e.g.:
This is equivalent to
t0 JOIN (t1 JOIN t2 ON c1) ON c2per the SQL standard'sright-associative interpretation when parentheses are absent. The parser already
handles this for Snowflake via
supports_left_associative_joins_without_parens();PostgreSQL was missing the override, causing a parse error on any right-deep chain
of depth >= 3.
Also filed upstream: apache#2377
cargo test --test sqlparser_postgrespasses locally (180 tests).Note
Low Risk
Parser and dialect-flag changes only; scope is SQL join parsing for PostgreSQL with targeted tests and no auth or data-path impact.
Overview
PostgreSQL now opts out of left-associative join parsing so chains like
t0 JOIN t1 JOIN t2 ON c1 ON c2parse and canonicalize to nested joins (e.g.t0 JOIN (t1 JOIN t2 ON c1) ON c2), matching Postgres right-deep join syntax.The join parser skips auto-wrapping in nested joins when the current join is NATURAL, so
NATURAL JOINfollowed by a constrained join stays left-associative instead of being parenthesized like Snowflake-style right-deep chains.Shared join precedence tests are collapsed to one canonical form; new PostgreSQL tests cover multi-table right-deep chains and NATURAL + INNER JOIN.
Reviewed by Cursor Bugbot for commit 6be2947. Bugbot is set up for automated code reviews on this repo. Configure here.