Skip to content

TSQL: table structure options for Azure Synapse not supported #7428

@keen85

Description

@keen85

Azure Synapse Dedicated SQL Pool uses TSQL dialect, with some additions:
For CREATE TABLE the "structure" of the table (heap, clustered column store, clustered index) can be specified directly.
This seems not to be supported by sqlglot as of version 30.1.0.

Fully reproducible code snippet

import sqlglot

sqlglot.parse_one(
    read="tsql",
    sql="CREATE TABLE t1 (id INT) WITH (HEAP)",
)  # ✅ works

sqlglot.parse_one(
    read="tsql",
    sql="CREATE TABLE t1 (id INT) WITH (CLUSTERED COLUMNSTORE INDEX)",
)  # ❌ fails

sqlglot.parse_one(
    read="tsql",
    sql="CREATE TABLE t1 (id INT) WITH (CLUSTERED INDEX (id))",
) # ❌ fails
sqlglot.errors.ParseError: Expecting (. Line 1, Col: 52.
  CREATE TABLE t1 (id INT) WITH (CLUSTERED COLUMNSTORE INDEX)

Official Documentation
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-azure-sql-data-warehouse?view=azure-sqldw-latest#table-structure-options

I tried to define a custom dialect, but it did not help

import sqlglot
from sqlglot import TokenType
from sqlglot.dialects.tsql import TSQL
from sqlglot.tokens import Tokenizer

class DsqlDialect(TSQL):
    class Tokenizer(Tokenizer):
        KEYWORDS = {
            **Tokenizer.KEYWORDS,
            "CLUSTERED COLUMNSTORE INDEX": TokenType.INDEX,
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions