sqlglot icon indicating copy to clipboard operation
sqlglot copied to clipboard

Snowflake/T-SQL: ALTER TABLE emits unparseable ADD COLUMNS for grouped column adds

Open princejain756 opened this issue 1 month ago • 0 comments

For a grouped multi-column add, Snowflake and T-SQL output Hive-style ADD COLUMNS, which neither dialect's own grammar accepts:

>>> import sqlglot
>>> sql = "ALTER TABLE Payments ADD COLUMNS (Stock DECIMAL(38, 0) NOT NULL, dropid VARCHAR(500) NOT NULL)"
>>> sqlglot.parse_one(sql, read="hive").sql(dialect="snowflake")
'ALTER TABLE Payments ADD COLUMNS (Stock DECIMAL(38, 0) NOT NULL, dropid VARCHAR(500) NOT NULL)'
>>> sqlglot.parse_one(sqlglot.parse_one(sql, read="hive").sql(dialect="snowflake"), read="snowflake")
ParseError: Invalid expression / Unexpected token.

The same happens with dialect="tsql". In both dialects the valid form for adding several columns at once is ADD (a INT, b VARCHAR(5)) with no COLUMN/COLUMNS keyword, which reparses cleanly. Other dialects that emit ADD COLUMNS (...) are unaffected since their grammars accept it.

I have a fix on a branch that adds a generator flag so Snowflake and T-SQL emit ADD (...): https://github.com/tobymao/sqlglot/compare/main...princejain756:sqlglot:fix-add-columns-keyword (tests included for both dialects, full suite green). I could not open a second PR while #8713 is open, so reporting here.

princejain756 avatar Oct 21 '26 11:10 princejain756