fix(parse): end the OUTPUT column list at FROM - #343
Merged
Conversation
Row<DB, 'update users set name = @p1 output inserted.id from users where id = @p2'> // was { 'from users': number } `UPDATE ... OUTPUT ... FROM` is the common T-SQL shape for writing a row and returning it while joining against another table, and the docs describe OUTPUT support without excluding it. OutputClauseColumns accumulated entries until it saw `where` and nothing else, so the FROM clause was swallowed into the list and `inserted.id from users` parsed as a single column entry whose alias was `from users`. `from` now ends the list the same way `where` does, for both UPDATE and DELETE. IsKeyword compares through Lowercase, which distributes over a union, so the stop keyword can be one. Fixes #300 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/300-tsql-output-from
branch
from
August 2, 2026 13:04
015379e to
2d443c9
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 #300.
The bug
Expected
{ id: number }. The docs describe OUTPUT support without excluding theUPDATE ... FROMform, and this variant is common in real T-SQL.The fix
OutputClauseColumns<S, 'where'>accumulated entries until it sawwhereand nothing else, sofromdid not stop it andinserted.id from usersbecame a single column entry thatParseColumnEntryread as a bare alias.fromnow ends the list the same waywheredoes, for both UPDATE and DELETE.IsKeywordcompares throughLowercase, which distributes over a union, so the existing stop-keyword parameter takes'where' | 'from'without any other change.Verification
tests/tsql-output-from.test-d.ts, seven cases. Four red on master:UPDATE ... OUTPUT ... FROM ... WHERE, one column and several, the DELETE form, and the strict-mode variantThe strict case is worth reading:
inserted.is stripped before resolution, so an OUTPUT column is looked up against both sources — the test usesinserted.name, which onlyusershas, and qualifies the WHERE. That is existing behaviour, unchanged here.Controls: OUTPUT without a FROM, OUTPUT as the last clause, and
RETURNINGare all unchanged.tsc --noEmitclean, 192 runtime tests pass, budget 192,547 (+61).