You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] JSQLParser 5.4 : MS SQL Server / Snowflake : ALTER TABLE t ADD a int, b int keeps only the first column, the rest becomes one UNSPECIFIC expression #2837
T-SQL and Snowflake let one ADD list several columns (and, in T-SQL, table constraints) without repeating ADD. JSqlParser parses the first column correctly. Everything after the first comma ends up in a single AlterOperation.UNSPECIFIC expression whose getOptionalSpecifier() holds the rest as re-spaced raw text. There is no parse error, and simple cases deparse to the original SQL, so it goes unnoticed. Tools that walk getColDataTypeList() see only the first column.
The cause: AlterTable() splits on ,, the ADD column branch takes a single AlterExpressionColumnDataType(), and the next item (b int) only matches the captureRest() fallback in AlterExpression(). #1651 reported the same statement in 2022, back when it still threw a parse error.
SQL Example:
ALTERTABLE t ADD a int, b varchar(10) NOT NULL, c int;
ALTERTABLE t ADD a int, CONSTRAINT ck CHECK (a >0);
ALTERTABLE t ADD COLUMN a int, b int; -- Snowflake
Alteralter = (Alter) CCJSqlParserUtil.parse("ALTER TABLE t ADD a int, b varchar(10) NOT NULL, c int");
for (AlterExpressione : alter.getAlterExpressions()) {
System.out.println(e.getOperation() + " | " + e.getColDataTypeList() + " | " + e.getOptionalSpecifier());
}
Actual (5.3; the grammar is the same in 5.4 and master):
ADD | [a int] | null
UNSPECIFIC | null | b varchar ( 10 ) NOT NULL , c int
The second statement gives ADD [a int] and UNSPECIFIC "CONSTRAINT ck CHECK ( a > 0 )". The third gives ADD [a int] and UNSPECIFIC "b int".
Expected: one ADD expression whose getColDataTypeList() is [a int, b varchar (10) NOT NULL, c int], as for ADD (a int, b int). For T-SQL, the CONSTRAINT ck CHECK (a > 0) item should come back as a constraint, not as raw text. Deparsing should keep the single ADD.
Software Information:
JSqlParser 5.3 and 5.4; master as of f6ac257 has the same grammar.
Activity
Parse T-SQL and Snowflake multi-item ADD lists
Parse T-SQL and Snowflake multi-item ADD lists (JSQLParser#2839)