Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ TOKEN:
* Supported tokens:
* - <S_IDENTIFIER>: Standard unquoted SQL identifier
* - <S_QUOTED_IDENTIFIER>: Quoted identifier (e.g., `identifier` or "identifier")
* - <K_NAME>, <K_NEXT>, <K_VALUE>, <K_PUBLIC>, <K_STRING>: Specific keywords treated as identifiers
* - <K_NAME>, <K_NEXT>, <K_VALUE>, <K_PUBLIC>, <K_STRING>, <K_DATA>: Specific keywords treated as identifiers
*
* @return Token representing the identifier or keyword used as identifier
*/
Expand All @@ -903,6 +903,7 @@ Token KeywordOrIdentifier():
| tk = <K_VALUE>
| tk = <K_PUBLIC>
| tk = <K_STRING>
| tk = <K_DATA>
)
{ return tk; }
}
Expand Down Expand Up @@ -9414,7 +9415,7 @@ AlterExpression AlterExpression():
<K_CHANGE> { alterExp.setOperation(AlterOperation.CHANGE); }
[ <K_COLUMN> { alterExp.hasColumn(true); alterExp.setOptionalSpecifier("COLUMN"); } ]
(
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER>)
(tk=KeywordOrIdentifier())
alterExpressionColumnDataType = AlterExpressionColumnDataType() { alterExp.withColumnOldName(tk.image).addColDataType(alterExpressionColumnDataType); }
)
)
Expand Down Expand Up @@ -9448,7 +9449,7 @@ AlterExpression AlterExpression():
( LOOKAHEAD(2) <K_COLUMN> { alterExp.hasColumn(true); } )?
[<K_IF> <K_EXISTS> { alterExp.setUsingIfExists(true); } ]
// @todo: replace with a proper identifier
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> | tk=<K_NAME>) { alterExp.setColumnName(tk.image); }
(tk=KeywordOrIdentifier() ) { alterExp.setColumnName(tk.image); }

[ "INVALIDATE" { alterExp.addParameters("INVALIDATE"); } ]

Expand Down
10 changes: 10 additions & 0 deletions src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ public void testAlterTableDropColumn2() throws JSQLParserException {
assertEquals("col2", col2Exp.getColumnName());
}

@Test
public void testAlterTableDropColumnIssue2339() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("ALTER TABLE test DROP COLUMN Data");
}

@Test
public void testAlterTableDropConstraint() throws JSQLParserException {
final String sql = "ALTER TABLE test DROP CONSTRAINT YYY";
Expand Down Expand Up @@ -455,6 +460,11 @@ public void testAlterTableChangeColumn4() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("ALTER TABLE tb_test CHANGE c1 c2 INT (10)");
}

@Test
public void testAlterTableChangeColumnIssue2339() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("ALTER TABLE tb_test CHANGE data INT (10)");
}

@Test
public void testAlterTableAddColumnWithZone() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
Expand Down