Skip to content

PostgreSQL: support right-deep join chains (deferred ON clauses)#3

Merged
moshap-firebolt merged 2 commits into
firebolt/v0.62.0-pathologicalfrom
moshap/pg-right-deep-joins
Jun 15, 2026
Merged

PostgreSQL: support right-deep join chains (deferred ON clauses)#3
moshap-firebolt merged 2 commits into
firebolt/v0.62.0-pathologicalfrom
moshap/pg-right-deep-joins

Conversation

@moshap-firebolt

@moshap-firebolt moshap-firebolt commented Jun 15, 2026

Copy link
Copy Markdown

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

cargo test --test sqlparser_postgres passes 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 c2 parse 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 JOIN followed 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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread src/dialect/postgresql.rs
moshap-firebolt and others added 2 commits June 14, 2026 20:20
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>
@moshap-firebolt moshap-firebolt force-pushed the moshap/pg-right-deep-joins branch from 64210ff to 6be2947 Compare June 15, 2026 03:21
@moshap-firebolt moshap-firebolt merged commit 5948ede into firebolt/v0.62.0-pathological Jun 15, 2026
2 checks passed
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.

1 participant