// SQLite error reference

SQLITE_ERROR: SQL logic error

SQLite's generic error code: a syntax error, a missing table or column, or another problem with the SQL. The real reason is in the error message, not the code.

Result code
SQLITE_ERROR
Name
1
Category
Primary result codes
Error message
SQL logic error

What it means

SQLITE_ERROR (1) is the code SQLite uses when no more specific code applies. Almost every mistake in the SQL itself lands here: a typo, a table or column that doesn't exist, a table that already exists, a wrong number of values. The generic text is SQL logic error; the message from sqlite3_errmsg() says what actually went wrong, for example no such table: users, no such column: emial, near "FORM": syntax error or table users already exists.

Because one code covers so many problems, always log and read the message.

Common causes

  • A syntax error: near "...": syntax error points at the token where parsing failed.
  • no such table: the table name is misspelled, it lives in an attached database you didn't qualify, or the program opened a different (often new and empty) database file than you think.
  • no such column: a misspelled column, or a string literal written in double quotes that SQLite took as a column name.
  • table ... already exists from a CREATE TABLE without IF NOT EXISTS.
  • Using syntax or functions that your SQLite version is too old to support, such as RETURNING (3.35) or window functions (3.25).

How to fix it

  1. Read the full message and fix what it names. Check the schema you are actually connected to:

    SELECT name, type FROM sqlite_schema ORDER BY name;
    PRAGMA table_info(users);
  2. If a table is missing, check which file is open. A relative path opens a file relative to the process's working directory, and opening a path that doesn't exist creates a new empty database.

    PRAGMA database_list;
  3. Use single quotes for string literals and double quotes only for identifiers.

    SELECT * FROM users WHERE status = 'active';
  4. Check the library version when newer syntax fails.

    SELECT sqlite_version();

Reproduce it safely

SELECT * FROM no_such_table;   -- Parse error: no such table: no_such_table

Related errors

More primary result codes errors

The code and message text are from the SQLite result and error codes documentation. Browse the full SQLite error list or search every database error.

// fewer errors, faster fixes

Work on SQLite in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQLite and the other databases you use.