Skip to content

Commit a6da400

Browse files
authored
fix(parser): allow VERSION in ALTER column clauses (#2530)
VERSION is non-reserved, but restricted legacy productions reject it in DROP COLUMN and USING clauses. Accept the token in those productions and cover both PostgreSQL corpus cases.
1 parent 125de36 commit a6da400

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,7 @@ Token KeywordOrIdentifier():
22442244
| tk = <K_STRING>
22452245
| tk = <K_DATA>
22462246
| tk = <K_TYPE>
2247+
| tk = <K_VERSION>
22472248
)
22482249
{ return tk; }
22492250
}
@@ -12065,7 +12066,7 @@ List<String> CreateParameter():
1206512066
|
1206612067
(
1206712068
//@todo: implement a proper identifier
12068-
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> | tk=<K_NAME>)
12069+
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> | tk=<K_NAME> | tk=<K_VERSION>)
1206912070
{ retval+=tk.image; }
1207012071

1207112072
[

‎src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,15 @@ public void testAlterTableAlterColumnDropNotNullIssue918() throws JSQLParserExce
648648
"ALTER TABLE \"user_table_t\" ALTER COLUMN name DROP NOT NULL");
649649
}
650650

651+
@Test
652+
public void testAlterTableVersionColumn() throws JSQLParserException {
653+
assertSqlCanBeParsedAndDeparsed(
654+
"ALTER TABLE test_table DROP COLUMN version, DROP COLUMN other_column");
655+
assertSqlCanBeParsedAndDeparsed(
656+
"ALTER TABLE test_table ALTER COLUMN version TYPE VARCHAR(32) "
657+
+ "USING version::VARCHAR(32)");
658+
}
659+
651660
@Test
652661
public void testAlterTableRenameColumn() throws JSQLParserException {
653662
// With Column Keyword

0 commit comments

Comments
 (0)