Skip to content

Commit 744dfc1

Browse files
committed
fix(parser): allow VERSION in ALTER column clauses
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 9a32ff5 commit 744dfc1

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
@@ -2140,6 +2140,7 @@ Token KeywordOrIdentifier():
21402140
| tk = <K_STRING>
21412141
| tk = <K_DATA>
21422142
| tk = <K_TYPE>
2143+
| tk = <K_VERSION>
21432144
)
21442145
{ return tk; }
21452146
}
@@ -11942,7 +11943,7 @@ List<String> CreateParameter():
1194211943
|
1194311944
(
1194411945
//@todo: implement a proper identifier
11945-
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> | tk=<K_NAME>)
11946+
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> | tk=<K_NAME> | tk=<K_VERSION>)
1194611947
{ retval+=tk.image; }
1194711948

1194811949
[

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)