Skip to content

feat(rds): joins, subquery sources and column aliases in select - #352

Merged
bentsku merged 1 commit into
mainfrom
rds-select-joins
Nov 18, 2026
Merged

bentsku merged 1 commit into
mainfrom
rds-select-joins

Conversation

@bentsku

@bentsku bentsku commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Problem

@aws-appsync/utils/rds declares three select() inputs we did not handle:

  • alias objects in columns, e.g. columns: [{ sys_i: 'item.sys_i' }], rejected with Invalid type in column array.
  • a subquery aliased in from, e.g. from: { item: select(...) }, rejected with Table alias value is expected to be a string.
  • the join keys (join, leftJoin, …, fullOuterJoinNatural), silently dropped: the SQL had no JOIN and no error was raised, so a resolver relying on a join returned wrong data

What this does

Behaviour recorded from EvaluateCode:

  • Column aliases render like table aliases, value first: { n: 'p.name' } → "p"."name" as "n". Only a string value is accepted; an aliased * is quoted. returning and using share the column list, so they accept aliases too.
  • Subquery sources: from: { s: select(...) } or from: { s: sql... } renders (...) as "s", with the subquery's variables numbered first. A bare statement as from, an insert as the aliased value, or a statement under table are rejected with AWS's messages.
  • Joins render between FROM and WHERE. Each item takes table or from (same rules as the select's own), and on (a sql template or a condition object) or using. AWS quirks reproduced:
    • a select applies only one join kind, the first present in a fixed order that interleaves natural and plain kinds (probed over every pair, independent of key order)
    • an on condition object binds its values as variables, like where, and accepts only strings and type hints (ON expects a string value comparisons.), so { 'u.x': { eq: 't.x' } } compares against the string 't.x'
    • join items that are not objects are skipped; using: [] renders USING (); only the applied kind is validated

renderSelect is split out of the statement switch so a subquery can render inline with shared variable numbering.

Not covered here: rds.agg aggregates, groupBy and having, which follow in the next PR along with the version bump and changelog.

Tests

New __tests__/rds-select.test.js, 100 cases recorded against AWS: each alias, source and join kind, the precedence chain as adjacent pairs, variable ordering across source, joins and where, and the validation errors. The full suite passes.

🤖 Generated with Claude Code

rds.select() now renders the join keys (all fifteen kinds, with `on` or
`using`), a subquery aliased in `from` (a select or a sql template), and
alias objects in `columns` and `returning`. Joins were previously
dropped from the generated SQL without an error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bentsku
bentsku added this pull request to stack #354 November 18, 2026 16:50
@bentsku
bentsku marked this pull request as ready for review November 18, 2026 16:58
@bentsku
bentsku merged commit 7ac99e7 into main Nov 18, 2026
4 checks passed
@bentsku
bentsku deleted the rds-select-joins branch November 18, 2026 16:59
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