PostgreSQL: support right-deep join chains (deferred ON clauses)#2377
Open
moshap-firebolt wants to merge 1 commit into
Open
PostgreSQL: support right-deep join chains (deferred ON clauses)#2377moshap-firebolt wants to merge 1 commit into
moshap-firebolt wants to merge 1 commit into
Conversation
moshap-firebolt
added a commit
to firebolt-analytics/datafusion-sqlparser-rs
that referenced
this pull request
Jun 15, 2026
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>
PostgreSQL accepts `t0 JOIN t1 JOIN t2 ON c1 ON c2` where ON clauses follow all JOIN keywords, associating right-to-left. Enable this by overriding supports_left_associative_joins_without_parens() to false for PostgresqlDialect, matching Snowflake's existing behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
18e75c0 to
078bed4
Compare
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. PostgreSQL documents
this in its JOIN syntax:
https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-JOIN
The parser already handles this correctly for dialects that return
falsefromsupports_left_associative_joins_without_parens()(Snowflake does this). ThePostgreSQL dialect was missing the override and fell through to the default
true,causing a parse error on any right-deep chain of depth >= 3.
This adds the override and a test that verifies both the parse and the canonical
round-trip serialization (with explicit parens).
cargo test --all-featurespasses locally.