Skip to content

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

Closed

Description

@mathiasrw

Four IF [NOT] EXISTS forms are parse errors in alasql. SQLite runs all four. Checked on 4.20.1:

alasql('CREATE INDEX IF NOT EXISTS i1 ON s (a)');                        // Parse error
alasql('DROP INDEX IF EXISTS i1');                                       // Parse error
alasql('CREATE TRIGGER IF NOT EXISTS tr1 BEFORE INSERT ON s CALL f()');   // Parse error
alasql('DROP TRIGGER IF EXISTS tr1');                                    // Parse error

The same forms already work for tables and views (CREATE VIEW IF NOT EXISTS, DROP VIEW IF EXISTS).

Why 4.x

Adding them is not breaking: every statement is a parse error today. They also give a clean way to write setup and clean-up code that runs more than once. Today that code depends on CREATE TRIGGER replacing an existing trigger (#2755) and DROP INDEX of a missing index returning 1 (#2759). Those stay as they are in the alasql dialect, but the sqlite dialect will throw, as SQLite does. The IF [NOT] EXISTS forms work the same in every dialect.

Behaviour

As for tables: the statement does nothing when the index or trigger already exists (CREATE ... IF NOT EXISTS) or does not exist (DROP ... IF EXISTS), and returns 0.

Grammar change: yarn jison, and the conflict count must stay at the baseline.

Related: #2755, #2759.

Activity

  1. added this to the v4.x Focus milestone on Oct 21, 2026
  2. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

    Hi, I'd like to work on this one.

  3. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

    Hi, I've opened a PR for this: #3028

  4. added a commit that references this issue on Nov 16, 2026
    7873899
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions