Skip to content

Comments

MSSQL: Add support for OUTPUT clause on INSERT/UPDATE/DELETE#2228

Open
guan404ming wants to merge 1 commit intoapache:mainfrom
guan404ming:mssql-output-clause
Open

MSSQL: Add support for OUTPUT clause on INSERT/UPDATE/DELETE#2228
guan404ming wants to merge 1 commit intoapache:mainfrom
guan404ming:mssql-output-clause

Conversation

@guan404ming
Copy link
Member

Why

MSSQL's OUTPUT clause allows returning inserted/deleted column values from DML statements, but was only supported on MERGE.

How

  • Add output: Option to Insert, Delete, and Update AST structs with correct mid-statement positioning
  • Reserve OUTPUT and VALUES keywords for table/column alias contexts to prevent ambiguous parsing
  • Add tests covering OUTPUT with and without INTO on all three statement types

Signed-off-by: Guan-Ming Chiu <guanmingchiu@gmail.com>
@guan404ming guan404ming marked this pull request as ready for review February 21, 2026 19:36
pub on: Option<OnInsert>,
/// RETURNING
pub returning: Option<Vec<SelectItem>>,
/// OUTPUT (MSSQL)
Copy link
Contributor

Choose a reason for hiding this comment

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

for these comments, could we include the link to the mssql docs describing the syntax? it would help with nagivation when folks look at the struct

Comment on lines +13292 to +13293
// MSSQL OUTPUT clause appears after FROM table, before USING/WHERE
// https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// MSSQL OUTPUT clause appears after FROM table, before USING/WHERE
// https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql

Comment on lines +17271 to +17272
// MSSQL OUTPUT clause appears between columns and source
// https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// MSSQL OUTPUT clause appears between columns and source
// https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql

Comment on lines +17505 to +17506
// MSSQL OUTPUT clause appears after SET, before FROM/WHERE
// https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// MSSQL OUTPUT clause appears after SET, before FROM/WHERE
// https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql

maybe we can introduce a helper function maybe_parse_output_clause() that can be called from the relevant statement parsing functions?

Comment on lines +2734 to +2736
// MSSQL OUTPUT clause on INSERT/UPDATE/DELETE
// https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// MSSQL OUTPUT clause on INSERT/UPDATE/DELETE
// https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql

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.

2 participants