When defining a model with dialect tsql, SQLMesh fails to parse valid SQL Server syntax that uses FOR JSON AUTO (or FOR JSON PATH).
This syntax is supported in SQL Server since 2016, but SQLMesh throws a parsing error instead of accepting the query.
config.yaml:
gateways:
local:
connection:
type: mssql
host: <localhost>
database: <DB>
driver: pymssql
user: <user>
password: <password>
port: 1433
trust_server_certificate: True
default_gateway: local
# --- Model Defaults ---
# https://sqlmesh.readthedocs.io/en/stable/reference/model_configuration/#model-defaults
model_defaults:
dialect: tsql
sample model:
MODEL (
name silver.policy,
kind FULL,
cron '@daily',
dialect tsql
);
SELECT
pol.policy_id,
pol.product_id
FROM silver.policy pol
FOR JSON AUTO
Error:
Error: Failed to load model from file '/analytics/warehouse/models/policy/silver/policy.sql': Invalid expression / Unexpected token. Line 15, Col: 3. ...(omitted)... <> '' �[4mFOR�[0m JSON PATH
Expected Behavior:
- SQLMesh should allow T-SQL specific syntax (FOR JSON AUTO, FOR JSON PATH, etc.) when dialect tsql is set.
- Query should be passed through to SQL Server instead of being rejected by the parser.
Environment:
- SQLMesh version: 0.202.1
- Database: SQL Server 2019
- Dialect: tsql
- OS: wsl (Ubuntu)
Additional Context:
- Verified that config.yaml points to mssql and default dialect is tsql.
- Removing FOR JSON AUTO makes the query parse successfully.
- JSON_ARRAYAGG is not an option because it requires SQL Server 2022, so SQL Server 2019 users rely on FOR JSON syntax.
When defining a model with dialect tsql, SQLMesh fails to parse valid SQL Server syntax that uses FOR JSON AUTO (or FOR JSON PATH).
This syntax is supported in SQL Server since 2016, but SQLMesh throws a parsing error instead of accepting the query.
config.yaml:
sample model:
Error:
Expected Behavior:
Environment:
Additional Context: