Repository navigation
Parse T-SQL and Snowflake multi-item ADD lists - #2839
Merged
manticore-projects merged 2 commits intoOct 22, 2026
Merged
Conversation
Contributor
|
Looks good, but can you please fix the Codazy exceptions regarding test method names. |
Contributor
Author
|
Renamed the new test methods to camelCase in 5e2cb05 - Codacy is green now. |
ALTER TABLE t ADD a int, b int parsed only the first column; the rest fell into a single UNSPECIFIC expression of raw text. T-SQL and Snowflake let one ADD list several column definitions and table constraints without repeating ADD. The ADD branch now loops on comma-separated items under the SQLSERVER and SNOWFLAKE dialects: each item is a column definition or a table constraint. A new bareAddList flag keeps the deparser from re-adding brackets T-SQL does not accept, and lets it emit a trailing constraint after the column list. Fixes JSQLParser#2837
princejain756
force-pushed
the
tsql-alter-add-list
branch
from
October 21, 2026 21:09
5e2cb05 to
c3774c2
Compare
Contributor
|
Thank you much! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ALTER TABLE t ADD a int, b intparsed only the first column. Everything after the first comma fell into a singleAlterOperation.UNSPECIFICexpression holding raw re-spaced text, so tools walkinggetColDataTypeList()saw justa int(#2837, also reported as a parse error back in #1651).T-SQL and Snowflake let one
ADDlist several column definitions and table constraints without repeatingADD. TheADDbranch ofAlterExpressionAddAlterModifynow loops on comma-separated items under theSQLSERVERandSNOWFLAKEdialects. Each item is either a column definition or, when it starts withCONSTRAINT/CHECK/PRIMARY/UNIQUE/FOREIGN, aTableConstraint. A new semantic lookahead (isAlterAddListItemAhead) keeps the loop from claiming commas that start a separate alter action, and the dialect gate leaves every other grammar path unchanged.Deparsing needed one model flag:
AlterExpressionunconditionally wrapped multi-column lists in brackets, which T-SQL does not accept, and dropped a constraint when columns were present. The newbareAddListflag, set only when this list form is parsed, keeps the output unbracketed and emits a trailing constraint after the column list. Programmatically built expressions keep the existing bracketed output.Test plan
ALTER TABLE t ADD a int, b varchar(10) NOT NULL, c intunder SQLSERVER parses as oneADDwithcolDataTypeListof 3 and round-tripsALTER TABLE t ADD a int, CONSTRAINT ck CHECK (a > 0)under SQLSERVER attaches a real constraint, notUNSPECIFICtextALTER TABLE t ADD COLUMN a int, b intunder SNOWFLAKE parses both columnsAlterTest; full suite 10,738 tests, 0 failures