Repository navigation
fix: accept non-reserved keywords as existing names in ALTER TABLE and CREATE SCHEMA - #2968
Merged
manticore-projects merged 1 commit intoDec 2, 2026
Conversation
…d CREATE SCHEMA Signed-off-by: minleejae <mmj9808@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ALTER TABLEread the name of an existing column, index or constraint throughKeywordOrIdentifier()or a bare<S_IDENTIFIER> | <S_QUOTED_IDENTIFIER>choice, andCREATE SCHEMAread its names the same way. These took plain identifiers plus nine keywords, or no keyword at all, so a column, index or constraint named by any other non-reserved keyword or by a type name such asnumber,enumorboolcould be created but not dropped or renamed.ALTER TABLE t DROP COLUMN link,ALTER TABLE t CHANGE level level INT,ALTER TABLE t RENAME COLUMN action TO cycle,ALTER TABLE t DROP INDEX link,ALTER TABLE t RENAME INDEX link TO status,ALTER TABLE t DROP CONSTRAINT IF EXISTS levelandCREATE SCHEMA linkwere parse errors, whileADD COLUMN link INTandAFTER linkparsed, as they useRelObjectName().This change reads these names with
RelObjectName(), the production of the other name positions:DROP [COLUMN] [IF EXISTS] name,CHANGE [COLUMN] old new ...,RENAME [COLUMN] old TO new,DROP {INDEX | KEY} name,RENAME {INDEX | KEY | CONSTRAINT} old TO new,DROP CONSTRAINT [IF EXISTS] name, and the catalog, schema andAUTHORIZATIONnames ofCREATE SCHEMA.INDEX,KEY,PRIMARYandPARTITIONare not reserved, so afterDROPthey keep their meaning when a name (orKEY) follows and name the column otherwise, as in PostgreSQL'sALTER TABLE t DROP key. AfterRENAME,INDEX,KEYandCONSTRAINTneed a name andTO, soRENAME key TO k2renames a column.CHANGEjoinsTABLEandCOLUMNinisReservedKeywordAsIdentifier()as a keyword that is always followed by a name, soCHANGE value v INTkeeps parsing.CREATE SCHEMAname still ends atAUTHORIZATIONand at a MySQL database option, and a plain identifier is still the name (CREATE SCHEMA charset).KeywordOrIdentifier()has no callers left and is removed.Compatibility: parser result classes and their public methods are unchanged, and statements that parsed before give the same model and
toString(). The generated parser loses theKeywordOrIdentifier()production, which had no other callers. JSqlParser keeps one set of reserved words for all dialects, so likeALTER TABLE t ADD COLUMN key INT, which it already takes,Dialect.MYSQLnow also takesALTER TABLE t DROP keyandRENAME key TO k2, which MySQL rejects becauseKEYis reserved there; likewiseDROP primarywithDialect.POSTGRESQL.Not changed: the reserved words that
isReservedKeywordAsIdentifier()admits only in some positions (OFFSET,ONLY,RETURNING,SET,BETWEEN) still fail afterDROP,INDEX,KEYorTO;SIMILARbeforeTOis still lexed asSIMILAR TO; a schema namedAUTHORIZATION,CHARACTER,COLLATEorENCRYPTIONstill fails.Reference: MySQL 8.4 ALTER TABLE, CREATE DATABASE, Keywords and Reserved Words; PostgreSQL 18 ALTER TABLE, CREATE SCHEMA, SQL Key Words.
Validation
KeywordsTest: every non-reserved keyword (445) as the column ofDROP COLUMN,DROP COLUMN IF EXISTS,CHANGE COLUMNandAFTER; as the index ofDROP INDEXandDROP KEYand the constraint ofDROP CONSTRAINT [IF EXISTS]; as both names ofRENAME COLUMN,RENAME INDEX,RENAME KEYandRENAME CONSTRAINT; as the catalog, schema andAUTHORIZATIONnames ofCREATE SCHEMA; type names andvaluein these positions withoutCOLUMN; andDROP key/DROP KEY k,DROP primary/DROP PRIMARY KEY,DROP partition/DROP PARTITION p1, p2,RENAME key TO k2/RENAME KEY k TO k2,CREATE SCHEMA AUTHORIZATION link,CREATE SCHEMA DEFAULT CHARACTER SET utf8mb4andCREATE SCHEMA charset, each checked against the model it should give. 1,751 of the 1,782 new cases fail on the base (2ba80d35c).PREPAREonly) and PostgreSQL 18.6 accepted all 21 and 18 statements of this change I checked, and rejected onlyDROP key/RENAME key TO k2(MySQL) andDROP primary(PostgreSQL), noted above.gradle check(Spotless, Checkstyle, PMD, JaCoCo verification) andcheckGrammarAmbiguity: 18,620 tests, 0 failures, 25 skipped; no choice conflicts.AI assistance: prepared with Claude Code.