Skip to content

fix: schema-qualified table handling in SQL Server - #184

Open
aambayec wants to merge 2 commits into
go-gorm:masterfrom
aambayec:fix/tableexpr-schema
Open

fix: schema-qualified table handling in SQL Server#184
aambayec wants to merge 2 commits into
go-gorm:masterfrom
aambayec:fix/tableexpr-schema

Conversation

@aambayec

Copy link
Copy Markdown
  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

This PR fixes schema-qualified table handling in the SQL Server driver.

The SQL Server-specific Create and MergeCreate callbacks used
Statement.Table directly when generating IDENTITY_INSERT and MERGE
statements, causing the schema to be omitted when using
db.Table("schema.table").

This change uses clause.CurrentTable instead, allowing GORM's core
quoting logic to honor Statement.TableExpr.

Regression tests have been added for both Create and Save using
schema-qualified tables.

User Case Description

Applications may target tables in different schemas by using
db.Table("schema.table").

Before this change, Create and Save generated SQL that omitted the
schema in SQL Server-specific statements (IDENTITY_INSERT and MERGE),
resulting in errors such as "Invalid object name".

After this change, schema-qualified table names are preserved
consistently throughout SQL generation.

Note: The regression tests reproduce the issue on the current implementation and pass after this fix is applied.

ahapin added 2 commits July 28, 2026 16:44
Use clause.CurrentTable instead of Statement.Table when generating
IDENTITY_INSERT and MERGE statements.

This allows GORM's core Statement.QuoteTo logic to honor
Statement.TableExpr for schema-qualified tables created via
db.Table("schema.table").
@aambayec aambayec changed the title Fix/tableexpr schema fix: schema-qualified table handling in SQL Server Jul 28, 2026
@aambayec

Copy link
Copy Markdown
Author

The CI failure appears unrelated to this change. The workflow is failing while parsing go.mod with invalid go version '1.24.0', before any of the modified code or tes

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