Skip to content

FTS4 triggers fail when indexed rows are updated or deleted #922

Open

Description

@Muguett-DBY

With fts_version="FTS4" and create_triggers=True, updating or deleting an indexed row raises sqlite3.OperationalError: SQL logic error:

from sqlite_utils import Database

db = Database(memory=True)
table = db.table("notes")
table.insert({"id": 1, "text": "alpha"}, pk="id")
table.enable_fts(["text"], fts_version="FTS4", create_triggers=True)
table.update(1, {"text": "beta"})  # sqlite3.OperationalError: SQL logic error

Deleting the indexed row also raises the error. The same update and delete work with fts_version="FTS5". I reproduced this with sqlite-utils 4.2.1, Python 3.12.14 and SQLite 3.53.1 on Windows, and also checked the current db.py at 9c66bafa with the installed support modules.

The generated FTS4 update/delete triggers use the FTS5-style INSERT ... VALUES('delete', ...) command after the content row changes. SQLite's FTS4 external-content documentation instead shows deleting the index entry before the content row changes, with the new entry inserted afterward. This is separate from the iterator issue in #902. Codex assisted with the investigation and checks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions