-
Notifications
You must be signed in to change notification settings - Fork 238
Open
Labels
BugSomething isn't workingSomething isn't working
Description
Take this simple MSSQL model for example:
MODEL (
name s.t,
kind INCREMENTAL_BY_UNIQUE_KEY (
unique_key (c)
)
);
SELECT
'ab' AS c
Since SQLMesh (i.e., SQLGlot) infers the column's type to be VARCHAR
, the model is considered "annotated", so instead of creating its snapshot's table with a CTAS query, we use create_table
for it directly here.
Unfortunately, using the VARCHAR
type in an MSSQL CREATE TABLE
statement results in a VARCHAR(1)
actual type under the hood, so the model's evaluation fails with the following error:
OperationalError:
(2628, b"String or binary data would be truncated in table 'master.sqlmesh__s.s__t__4201193267', column 'c'. Truncated value: 'a'.DB-Lib error message 20018, severity 16:\nGeneral
SQL Server error: Check messages from the SQL Server\n")
A couple of ideas that we can consider are:
- Avoid using inferred types in DDL statements, either generally or specifically for MSSQL
- Ensure plain
VARCHAR
types are generated asVARCHAR(MAX)
for MSSQL DDL statements, to avoid truncation issues.
Relevant Slack thread for reference: https://tobiko-data.slack.com/archives/C044BRE5W4S/p1751937537407689
codykonior
Metadata
Metadata
Assignees
Labels
BugSomething isn't workingSomething isn't working