Repository navigation
fix: read keywords of other dialects as names with Dialect.MYSQL and Dialect.POSTGRESQL - #2969
Merged
manticore-projects merged 1 commit intoDec 2, 2026
Conversation
…Dialect.POSTGRESQL Signed-off-by: minleejae <mmj9808@gmail.com>
minleejae
force-pushed
the
fix/dialect-foreign-keywords-20261202
branch
from
December 2, 2026 07:59
96f1eb7 to
4d69ad3
Compare
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.
JSqlParser reserves some words for clauses of other dialects in every dialect, so with
Dialect.MYSQLorDialect.POSTGRESQLa column, table, constraint or alias namedfinal,output,pivot,minusorsemiwas a parse error, although neither MySQL 8.4 nor PostgreSQL 18 knows these words as keywords:CREATE TABLE t (id INT, final INT),ALTER TABLE t ADD COLUMN output INT,SELECT a FROM t pivotor, with PostgreSQL,SELECT xor, use FROM t.With these two dialects, the keywords that the dialect does not have are now plain names:
Dialect.MYSQL:CONNECT_BY_ROOT,EXCLUDES,FINAL,ILIKE,INCLUDES,MINUS,NOCYCLE,OUTPUT,PIVOT,PREFERRING,SEMI,TOP,UNPIVOT.Dialect.POSTGRESQL: the same words exceptILIKE, which PostgreSQL reserves, plusQUALIFY,USE,XORand MySQL'sDISTINCTROW,SQL_CACHE,SQL_CALC_FOUND_ROWSandSTRAIGHT_JOIN.isDialectIdentifierKeyword()holds the two lists.RelObjectName()takes these keywords in an alternative of their own, which comes before the guarded reserved keywords becauseisReservedKeywordAsIdentifier()checks the position only.isIdentifierishNameToken()andisAliasAhead()follow the same check. Where one of these words would start a clause, an operator or a modifier, that reading is skipped with the dialect:SEMI JOIN,XOR,ILIKE,INCLUDES,EXCLUDES,CONNECT_BY_ROOT,CONNECT BY NOCYCLE,TOP, MySQL's select modifiers andDISTINCTROW, and a trailing select-list comma beforeMINUS. Two spots needed a different shape, because JavaCC does not evaluate a semantic check inside[ ... ]or( ... )*while scanning ahead: theSTRAIGHT_JOINhint afterSELECTbecomes a choice with an empty alternative, and theSTRAIGHT_JOIN,SQL_CALC_FOUND_ROWSandSQL_CACHEalternatives ofMySqlSelectModifier()carryisMySqlSelectModifierAhead()themselves.Compatibility: without a dialect and with every other dialect, nothing changes, and these words keep their clauses (
SELECT * FROM t FINAL,... MINUS SELECT ...,a XOR b,LEFT SEMI JOIN,SELECT TOP 10). MySQL keepsXOR,DISTINCTROW,STRAIGHT_JOINandSQL_CALC_FOUND_ROWS. Parser result classes and public methods are unchanged.Not changed:
SQL_CACHEstays a select modifier withDialect.MYSQL, which MariaDB and MySQL 5.7 still have.QUALIFYandTABLESAMPLEare non-reserved MySQL keywords with a clause of their own, so the existing position checks still decide them.SELis lexed asSELECT, and with the dialectMINUSstill joins two queries where no name can stand, such as after aWHEREcondition.Reference: MySQL 8.4 Keywords and Reserved Words, PostgreSQL 18 SQL Key Words.
Validation
KeywordsTest: each listed keyword with its dialect as table, column, constraint and index name inCREATE TABLE,ALTER TABLE ADD/DROP/RENAME COLUMNandCREATE INDEX, and as column, alias and table alias inSELECT,INSERTandUPDATE; without a dialectFINAL,MINUS,XOR,LEFT SEMI JOINandTOPkeep their clauses, MySQL keepsXORandDISTINCTROW, and PostgreSQL readsa xoras an alias. 31 of the 33 new cases fail on the base (5868b524b); the other two aretop, already a name there.PREPAREonly) accepted all 40 statements I checked with the MySQL words, and PostgreSQL 18.6 all 77 with the PostgreSQL words (CREATE TABLE,SELECTwith aliases,ADD COLUMN,RENAME COLUMN); the only errors were semantic, such as a missing table.gradle check(Spotless, Checkstyle, PMD, JaCoCo verification) andcheckGrammarAmbiguity: 18,686 tests, 0 failures, 25 skipped; no choice conflicts.AI assistance: prepared with Claude Code.