fix(parse): validate the SELECT half of an INSERT ... SELECT - #350
Merged
Conversation
StrictRow<DB, 'insert into users (name) select naem from ghosts where nope = 1'>
// was Record<string, never> - three mistakes accepted in one line
The INSERT branch extracted the target and the RETURNING/OUTPUT clause and
stopped there, so the trailing SELECT was never parsed as a statement: its
sources, its columns and its WHERE did not exist as far as validation was
concerned. The README says strict mode checks the SELECT list and the WHERE
clause, and this statement has both.
The parsed statement now carries the SELECT half, and strict mode resolves
it through the same entry point the outer query uses - so its CTEs, joins
and clause checks all apply, and an error surfaces as the row the way every
other strict failure does. The INSERT's own RETURNING columns still decide
the row shape when the SELECT half is clean.
Fixes #272
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/272-insert-select-strict
branch
from
August 2, 2026 13:04
4d94882 to
9acd4eb
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.
Fixes #272.
The bug
Three mistakes ride through in one line:
ghostsis not a table,naemis not a column, andnopeis not one either. The README says strict mode checks the SELECT list and the WHERE clause; this statement has both.The fix
The INSERT branch extracted the target and the RETURNING/OUTPUT clause and stopped. The parsed statement now carries the SELECT half as its own query text, and strict mode resolves it through the same entry point the outer query uses — so the nested statement's CTEs, joins, column resolution and clause checks all apply for free, and an error surfaces as the row, the way every other strict failure does.
When the SELECT half is clean, the INSERT's own RETURNING columns still decide the row shape.
Verification
tests/insert-select-strict.test-d.ts, nine cases. Three red on master:Controls: valid
INSERT ... SELECTwith and without a WHERE, one withRETURNING(still{ id: number }),INSERT ... VALUES, a plain SELECT, and loose mode.tsc --noEmitclean, 192 runtime tests pass, budget 194,103 (+1,617).