[MsSql] Exclude generated columns from INSERT column list#5882
Open
valerii-kuzivanov wants to merge 1 commit into
Open
[MsSql] Exclude generated columns from INSERT column list#5882valerii-kuzivanov wants to merge 1 commit into
valerii-kuzivanov wants to merge 1 commit into
Conversation
MsSqlColumn overrode shouldDisableInsert() with a hardcoded false,
masking the base Column logic that excludes generatedAlwaysAs columns
from inserts. As a result buildInsertQuery listed computed columns
with the `default` keyword and SQL Server rejected the statement with
error 271 ("The column cannot be modified because it is either a
computed column or is the result of a UNION operator").
Remove the override so the base logic applies, and keep the identity
exclusion in MsSqlColumnWithIdentity combined with the inherited check.
Fixes drizzle-team#5881
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 #5881
Problem
The MSSQL dialect's
buildInsertQueryemits every table column in the INSERT column list, filling missing values with thedefaultkeyword.MsSqlColumnoverridesshouldDisableInsert()with a hardcodedfalse, sogeneratedAlwaysAs()(computed) columns are included too — and SQL Server rejects any mention of a computed column in an INSERT column list, even withDEFAULT:This blocks inserting into any table with a computed column — including schemas produced by
drizzle-kit pull, which introspects SQL Server computed columns intogeneratedAlwaysAs().Fix
MsSqlColumn.shouldDisableInsert()override so the baseColumnlogic applies (the MSSQLgeneratedAlwaysAs()builder always setsgenerated.type: 'always', so computed columns are excluded). No other dialect overrides this method on its base column class.MsSqlColumnWithIdentity.shouldDisableInsert()now combines its identity exclusion with the inherited check.Tests
insert into table with generated columntointegration-tests/tests/mssql/mssql.test.ts: creates a table with a computed column, inserts through the query builder, and reads the computed value back. Fails with Msg 271 before the fix, passes after.mcr.microsoft.com/azure-sql-edge:mssql.test.ts159 passed / 0 failed;mssql.custom.test.ts+mssql.prefixed.test.ts+mssql.rels.test.ts186 passed / 0 failed.