Skip to content

Support IF [NOT] EXISTS for CREATE/DROP INDEX and TRIGGER to close #2775 - #3028

Merged
mathiasrw merged 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix/2775-if-exists-index-trigger
Nov 15, 2026
Merged

mathiasrw merged 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix/2775-if-exists-index-trigger

Conversation

@mateuscmtropical

Copy link
Copy Markdown
Contributor

Closes #2775

What was wrong

CREATE INDEX IF NOT EXISTS, DROP INDEX IF EXISTS, CREATE TRIGGER IF NOT EXISTS and DROP TRIGGER IF EXISTS were parse errors.

What changed

  • The CreateIndex, DropIndex, CreateTrigger and DropTrigger rules take the existing IfNotExists and IfExists clauses, as CREATE TABLE and DROP TABLE do. The grammar still has 282 conflicts.
  • With the clause, the statement does nothing and returns 0 when the index or trigger already exists (CREATE) or is missing (DROP). CREATE TRIGGER IF NOT EXISTS keeps the first trigger.
  • Without the clause nothing changes: DROP TRIGGER of a missing trigger still throws and DROP INDEX still returns 1.
  • toString prints the clause. DropIndex.toString also gets the missing space after DROP INDEX.

Tests

test/test2775.js runs each form twice, checks that the first trigger is kept, and checks toString. All of them are parse errors without the fix.

yarn test-only gives 2556 pass. The only failures are the 5 Test 418 cases that load files from the internet.

@mathiasrw mathiasrw added this to the v4.x Focus milestone Nov 15, 2026
@mathiasrw
mathiasrw merged commit 7873899 into AlaSQL:develop Nov 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CREATE INDEX IF NOT EXISTS, DROP INDEX IF EXISTS, CREATE TRIGGER IF NOT EXISTS and DROP TRIGGER IF EXISTS are parse errors

2 participants