Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSSQL: tsql,normalization_strategy=case_sensitive doesn't handle case changes properly on case insensitive collations #3923

Open
martinburch opened this issue Feb 28, 2025 · 3 comments
Assignees
Labels
Bug Something isn't working Engine: SQL Server

Comments

@martinburch
Copy link

martinburch commented Feb 28, 2025

When switching on case sensitivity, the database's case-insensitive comparisons allow the DROP VIEW IF EXISTS to succeed in dropping the newly-created view.

The order of the commands needs to be reversed: first, drop the view, then re-create it.
https://learn.microsoft.com/en-us/sql/relational-databases/views/rename-views?view=sql-server-ver16#TsqlProcedure

As a workaround, I can replay the CREATE OR ALTER VIEW commands from the SQLMesh log.

-  dialect tsql,                                                                                                                                                  
+  dialect [tsql,normalization_strategy=case_sensitive],   

SQLMesh correctly identifes

Models:
├── Added:
│   ├── a_o.O
├── Removed:
│   ├── a_o.o

However, the commands are in the wrong order:

2025-02-27 16:42:18,836 - ThreadPoolExecutor-4_1 - sqlmesh.core.engine_adapter.base - INFO - Executing SQL: CREATE OR ALTER VIEW [a_o].[O] AS SELECT * FROM [sql-prod].[a_o].[a_o__O__641323945]; (base.py:2079)

2025-02-27 16:42:19,635 - ThreadPoolExecutor-5_1 - sqlmesh.core.engine_adapter.base - INFO - Executing SQL: DROP VIEW IF EXISTS [a_o].[o]; (base.py:2079)

@lafirm
Copy link
Contributor

lafirm commented Mar 5, 2025

The order of the commands needs to be reversed: first, drop the view, then re-create it.

If we reverse the order like @martinburch said, that should solve this #3649 as well. just curious, is there any specific reason why we do create -> drop not drop -> create.

@izeigerman izeigerman added Bug Something isn't working Engine: SQL Server labels Mar 11, 2025
@izeigerman
Copy link
Member

@georgesittas can you please have a look

@georgesittas
Copy link
Contributor

@martinburch can you provide a complete example that I can use to reproduce the problem you're seeing? I'm not sure I understand what you're trying to achieve. I get that you changed the dialect setting to activate case-sensitivity for the T-SQL dialect, but is your database or your MSSQL server also case-sensitive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Engine: SQL Server
Projects
None yet
Development

No branches or pull requests

4 participants