Skip to content

Inferred column types may be invalid for MSSQL's DDL statements #4932

@georgesittas

Description

@georgesittas

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:

  1. Avoid using inferred types in DDL statements, either generally or specifically for MSSQL
  2. Ensure plain VARCHAR types are generated as VARCHAR(MAX) for MSSQL DDL statements, to avoid truncation issues.

Relevant Slack thread for reference: https://tobiko-data.slack.com/archives/C044BRE5W4S/p1751937537407689

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy