Skip to content

Allow specific keywords to be parsed as identifiers (fix issue with RENAME COLUMN) - #2203

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/rename
Mar 24, 2025
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/rename

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a new parser rule KeywordOrIdentifier() to handle cases where certain keywords are used as identifiers. This addresses issues that arose after specific tokens like NAME were introduced as keywords.

Problem

While parsing a statement like:

ALTER TABLE test_table RENAME COLUMN name TO full_name;

the parser failed because name was recognized strictly as a <K_NAME> keyword after this commit, instead of being allowed as an identifier.

Solution

  • Introduced KeywordOrIdentifier() rule that accepts:
    • <S_IDENTIFIER>
    • <S_QUOTED_IDENTIFIER>
    • Selected keywords like <K_NAME>, <K_NEXT>, <K_VALUE>, <K_PUBLIC>, <K_STRING>
    • Additional tokens can be added as needed in the future.
  • Replaced relevant parts of the grammar to use KeywordOrIdentifier().

I’m open to any feedback or suggestions on this approach!

@manticore-projects

Copy link
Copy Markdown
Contributor

We need to rework the whole keyword management eventually. But in the meantime this can be a remedy.

@manticore-projects
manticore-projects merged commit a068dd4 into JSQLParser:master Mar 24, 2025
@minleejae

Copy link
Copy Markdown
Contributor Author

Hi, @manticore-projects
I also agree that the current keyword handling could use a more systematic approach.
Out of curiosity, could you share your thoughts on what the ultimate direction for keyword management should look like? I'd like to align any future refactoring efforts accordingly.