GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: allow UNIQUE INDEX in CREATE TABLE by fudianchn · Pull Request #2457 · JSQLParser/JSqlParser

Conversation

@fudianchn

@fudianchn fudianchn commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

What

Allow an optional UNIQUE prefix on INDEX inside CREATE TABLE, so MySQL-style UNIQUE INDEX name (cols) ... parses and round-trips.

Why

MySQL accepts UNIQUE INDEX name (cols) ... as an inline table constraint (it is produced by tooling and appears in real schemas). JSQLParser currently rejects it:

net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "UNIQUE" "UNIQUE"

Only INDEX name (...) and [UNIQUE] KEY name (...) were accepted; the UNIQUE INDEX combination fell through every CreateTableConstraint alternative.

How

The INDEX branch of CreateTableConstraint now accepts an optional leading UNIQUE, and the index type is rendered as UNIQUE INDEX when present (mirroring the existing [UNIQUE] KEY branch). LOOKAHEAD(3) becomes LOOKAHEAD(4) to cover the extra token. The branches remain unambiguous: UNIQUE INDEX name ( matches this branch, UNIQUE KEY name ( still matches the [UNIQUE] ... KEY branch, and UNIQUE ( still matches the [CONSTRAINT] UNIQUE branch.

Testing

  • New CreateTableTest#testUniqueIndexIssue1893 — UNIQUE INDEX idx (a, b) USING BTREE COMMENT '...' round-trips (fails before the grammar change), and a plain INDEX idx (a) still parses.
  • ./gradlew test --tests net.sf.jsqlparser.statement.create.CreateTableTest — green.
  • Full ./gradlew test — no regressions introduced by this change. The 33 unrelated failures observed locally are pre-existing environmental issues (Mockito inline MockMaker does not initialise under the local JDK 17 / Windows toolchain, and ParserKeywordsUtilsTest resolves its temp file to C:\WINDOWS); both reproduce on unmodified master.

Fixes #1893

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fudianchn
fix: allow UNIQUE INDEX in CREATE TABLE
cabfedc
Accept an optional UNIQUE prefix on the INDEX branch of CreateTableConstraint, so MySQL-style CREATE TABLE ... UNIQUE INDEX name (cols) ... parses and round-trips. UNIQUE INDEX is disambiguated from UNIQUE KEY and the bare UNIQUE constraint by the LOOKAHEAD.

Fixes JSQLParser#1893

Signed-off-by: 付典 <[email protected]>
@manticore-projects
manticore-projects merged commit 32a7949 into JSQLParser:master Aug 10, 2026
7 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@manticore-projects

manticore-projects commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fudianchn
fudianchn deleted the feat/unique-index-create-table-1893 branch August 21, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "UNIQUE" "UNIQUE"

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@fudianchn @manticore-projects
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.