Skip to content

Commit 186f0ed

Browse files
fix(mssql): update SQL keywords to uppercase for consistency (#4795)
1 parent 96cc041 commit 186f0ed

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

sqlmesh/core/engine_adapter/mssql.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ def columns(
9090

9191
sql = (
9292
exp.select(
93-
"column_name",
94-
"data_type",
95-
"character_maximum_length",
96-
"numeric_precision",
97-
"numeric_scale",
93+
"COLUMN_NAME",
94+
"DATA_TYPE",
95+
"CHARACTER_MAXIMUM_LENGTH",
96+
"NUMERIC_PRECISION",
97+
"NUMERIC_SCALE",
9898
)
99-
.from_("information_schema.columns")
100-
.where(f"table_name = '{table.name}'")
99+
.from_("INFORMATION_SCHEMA.COLUMNS")
100+
.where(f"TABLE_NAME = '{table.name}'")
101101
)
102102
database_name = table.db
103103
if database_name:
104-
sql = sql.where(f"table_schema = '{database_name}'")
104+
sql = sql.where(f"TABLE_SCHEMA = '{database_name}'")
105105

106106
columns_raw = self.fetchall(sql, quote_identifiers=True)
107107

@@ -145,12 +145,12 @@ def table_exists(self, table_name: TableName) -> bool:
145145

146146
sql = (
147147
exp.select("1")
148-
.from_("information_schema.tables")
149-
.where(f"table_name = '{table.alias_or_name}'")
148+
.from_("INFORMATION_SCHEMA.TABLES")
149+
.where(f"TABLE_NAME = '{table.alias_or_name}'")
150150
)
151151
database_name = table.db
152152
if database_name:
153-
sql = sql.where(f"table_schema = '{database_name}'")
153+
sql = sql.where(f"TABLE_SCHEMA = '{database_name}'")
154154

155155
result = self.fetchone(sql, quote_identifiers=True)
156156

tests/core/engine_adapter/test_mssql.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_columns(adapter: MSSQLEngineAdapter):
7979
}
8080

8181
adapter.cursor.execute.assert_called_once_with(
82-
"""SELECT [column_name], [data_type], [character_maximum_length], [numeric_precision], [numeric_scale] FROM [information_schema].[columns] WHERE [table_name] = 'table' AND [table_schema] = 'db';"""
82+
"""SELECT [COLUMN_NAME], [DATA_TYPE], [CHARACTER_MAXIMUM_LENGTH], [NUMERIC_PRECISION], [NUMERIC_SCALE] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = 'table' AND [TABLE_SCHEMA] = 'db';"""
8383
)
8484

8585

@@ -149,8 +149,8 @@ def test_table_exists(make_mocked_engine_adapter: t.Callable):
149149
resp = adapter.table_exists("db.table")
150150
adapter.cursor.execute.assert_called_once_with(
151151
"""SELECT 1 """
152-
"""FROM [information_schema].[tables] """
153-
"""WHERE [table_name] = 'table' AND [table_schema] = 'db';"""
152+
"""FROM [INFORMATION_SCHEMA].[TABLES] """
153+
"""WHERE [TABLE_NAME] = 'table' AND [TABLE_SCHEMA] = 'db';"""
154154
)
155155
assert resp
156156
adapter.cursor.fetchone.return_value = None
@@ -506,7 +506,7 @@ def test_replace_query(make_mocked_engine_adapter: t.Callable):
506506
adapter.replace_query("test_table", parse_one("SELECT a FROM tbl"), {"a": "int"})
507507

508508
assert to_sql_calls(adapter) == [
509-
"""SELECT 1 FROM [information_schema].[tables] WHERE [table_name] = 'test_table';""",
509+
"""SELECT 1 FROM [INFORMATION_SCHEMA].[TABLES] WHERE [TABLE_NAME] = 'test_table';""",
510510
"TRUNCATE TABLE [test_table];",
511511
"INSERT INTO [test_table] ([a]) SELECT [a] FROM [tbl];",
512512
]

0 commit comments

Comments
 (0)