Skip to content

feat(parser/postgres): wire INNER JOIN queries through multi-table resolver - #49

Merged
JagritGumber merged 2 commits into
mainfrom
feat/postgres-parser-inner-join
Apr 20, 2026
Merged

feat(parser/postgres): wire INNER JOIN queries through multi-table resolver#49
JagritGumber merged 2 commits into
mainfrom
feat/postgres-parser-inner-join

Conversation

@JagritGumber

@JagritGumber JagritGumber commented Apr 20, 2026

Copy link
Copy Markdown
Owner

Re-opens #47 which auto-closed when its base branch was deleted during the #46 merge. Same changes, now based on main.


Open in Devin Review

…solver

When a query contains the JOIN keyword, route each SELECT column through
the multi-table resolver from parser::joins (landed in the prior PR).
Qualified columns now resolve across the alias map and land in QueryDef.returns
with source_table populated.

Queries without JOIN keep the existing single-table path unchanged —
ensure_supported_select_expr still rejects qualified selects there.
Lifting that restriction for single-table queries is a separate effort
(PR #32 was in flight before this series).

Changes:
- resolve_return_columns gains a &[TableDef] schema_tables param
- JOIN_DETECT_RE gates multi-table resolution
- resolve_return_columns_multi_table rejects SELECT * across joins with
  a clear v1.2 pointer
- Parser propagates schema_tables from parse_queries to resolve_return_columns

Tests:
- 5 new postgres parser unit tests (qualified columns, AS aliases, SELECT *
  rejection, LEFT JOIN rejection, single-table rejection still active)
- Updated the cli test that was asserting the old rejection — it now
  asserts the JOIN query succeeds (renamed from cli_generate_rejects_
  qualified_selects to cli_generate_accepts_multi_table_inner_join)

158 lib + 11 CLI + 2 e2e + 4 typecheck tests all pass. Clippy clean.
…ives

Devin flagged that `JOIN_DETECT_RE.is_match(sql)` matches `\bJOIN\b`
anywhere in the SQL, which false-triggers on queries where the JOIN
lives inside a subquery (e.g. `WHERE id IN (SELECT ... JOIN ...)`).
The outer query's single-table SELECT was then misrouted to the
multi-table resolver and failed with a confusing error.

Fix: route through `parser::joins::has_outer_join`, which scopes the
check to the outer FROM body via FROM_CLAUSE_RE. JOINs inside
subqueries stay behind the WHERE boundary and no longer trip the
outer detection.

Also drop the local JOIN_DETECT_RE static (was unused after the
switch) and the stale imports. New regression test covers the
subquery case end-to-end through parse_queries.
@JagritGumber
JagritGumber merged commit e212d8d into main Apr 20, 2026
2 of 3 checks passed
@JagritGumber
JagritGumber deleted the feat/postgres-parser-inner-join branch April 20, 2026 00:48

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

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