Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse column rename sql without COLUMN keyword #1516

Closed
jackiezh opened this issue Apr 22, 2022 · 1 comment · Fixed by #1533
Closed

Cannot parse column rename sql without COLUMN keyword #1516

jackiezh opened this issue Apr 22, 2022 · 1 comment · Fixed by #1533
Assignees

Comments

@jackiezh
Copy link

Describe the bug
Cannot parse column rename sql without COLUMN keyword.

To Reproduce
Steps to reproduce the behavior:

  1. Example SQL
    ALTER TABLE table_a RENAME col_a TO col_b;

  2. Parsing this SQL using JSqlParser with this statements
    CCJSqlParserUtil.parse("ALTER TABLE table_a RENAME col_a TO col_b");

  3. Exception
    net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "col_a" <S_IDENTIFIER>
    at line 1, column 28.

Was expecting:

"TO"

at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:31468)
at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:31301)
at net.sf.jsqlparser.parser.CCJSqlParser.AlterExpression(CCJSqlParser.java:17874)
at net.sf.jsqlparser.parser.CCJSqlParser.AlterTable(CCJSqlParser.java:17947)
at net.sf.jsqlparser.parser.CCJSqlParser.SingleStatement(CCJSqlParser.java:267)
at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:153)
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatement(CCJSqlParserUtil.java:188)

System

  • Database you are using: PostgreSQL
  • Java Version: java-1.8
  • JSqlParser version: 4.4
@manticore-projects
Copy link
Contributor

The supported Syntax is shown here: http://217.160.215.75:8080/jsqlformatter/_static/JSqlParserCC.xhtml#AlterTable

Indeed the COLUMN keyword is mandatory.
In PostgreSQL COLUMN is supported, but optional:
ALTER TABLE [ IF EXISTS ] [ ONLY ] name [ * ] RENAME [ COLUMN ] column_name TO new_column_name

@manticore-projects manticore-projects self-assigned this Apr 22, 2022
manticore-projects added a commit to manticore-projects/JSqlParser that referenced this issue May 9, 2022
wumpz pushed a commit that referenced this issue May 11, 2022
* Adjust Gradle to JUnit 5

Parallel Test execution
Gradle Caching
Explicitly request for latest JavaCC 7.0.10

* Do not mark SpeedTest for concurrent execution

* Remove unused imports

* Adjust Gradle to JUnit 5

Parallel Test execution
Gradle Caching
Explicitly request for latest JavaCC 7.0.10

* Do not mark SpeedTest for concurrent execution

* Remove unused imports

* `RENAME ... TO ...` without `COLUMN` keyword

Fixes #1516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants