Skip to content

[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

Closed

Description

Failing SQL Feature:

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:

ALTER TABLE t ADD a int, b varchar(10) NOT NULL, c int;
ALTER TABLE t ADD a int, CONSTRAINT ck CHECK (a > 0);
ALTER TABLE t ADD COLUMN a int, b int;   -- Snowflake
Alter alter = (Alter) CCJSqlParserUtil.parse("ALTER TABLE t ADD a int, b varchar(10) NOT NULL, c int");
for (AlterExpression e : 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:

Related: #1651, #246.

Activity

  1. added a commit that references this issue on Oct 21, 2026
    bc177f4
  2. added a commit that references this issue on Oct 22, 2026
    8ade7b0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions