Skip to content

feat: parse SQLite INSERT OR <algorithm> with the INSERT clauses - #2924

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
ItsDeadlyProgrammer:sqlite-insert-or
Nov 14, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
ItsDeadlyProgrammer:sqlite-insert-or

Conversation

@ItsDeadlyProgrammer

Copy link
Copy Markdown
Contributor

The INSERT OR <algorithm> form was parsed by the separate Upsert() production, so it rejected
the clauses the plain INSERT production supports:

INSERT INTO t (a) VALUES (1) RETURNING a                        -- parses
INSERT OR IGNORE INTO t (a) VALUES (1) RETURNING a              -- failed
INSERT OR IGNORE INTO t (a) VALUES (1) ON CONFLICT DO NOTHING   -- failed
INSERT OR IGNORE INTO t DEFAULT VALUES                          -- failed

Change

  • SingleStatement() reads INSERT OR <algorithm> with Insert(), behind Dialect.SQLITE.
  • Insert() accepts [ <K_OR> algorithm=RelObjectName() ] after <K_INSERT> and stores it as
    InsertConflictAlgorithm (OR_ABORT, OR_FAIL, OR_IGNORE, OR_REPLACE, OR_ROLLBACK),
    rendered by appendInsertPrefix(); Insert.omitInto keeps SQLite's optional INTO.
  • Upsert / UpsertDeParser are untouched: REPLACE without OR and PostgreSQL's UPSERT parse
    exactly as before. Folding REPLACE in touches callers that cast to Upsert (ReplaceTest,
    MySqlInsertSourceTest, ReplaceValidatorTest) and is left for a second PR.

Tests

SQLiteTest gains testInsertOrConflictAlgorithmIsAnInsert,
testInsertOrKeepsTheInsertClauses (ON CONFLICT, RETURNING, DEFAULT VALUES, alias) and
testInsertOrKeepsTheOptionalInto.

Full suite: 13112 tests, no new failures compared to master; SQLiteTest 41/41 green. A sweep of
all 322 .sql fixtures in src/test/resources produces identical parse results and deparsed output
on the patched and unpatched parser.
Part of #2852.

Read the algorithm in Insert() behind Dialect.SQLITE, so the OR-form keeps ON CONFLICT,
RETURNING, DEFAULT VALUES and the table aliases. REPLACE without OR keeps its Upsert reading.

Part of JSQLParser#2852
@manticore-projects
manticore-projects merged commit 07d5f32 into JSQLParser:master Nov 14, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

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.

2 participants