InletDownload

SQLite error SQLITE_ERROR

near "…": syntax error

SQLite’s parser reached the quoted word and couldn’t fit it into any valid statement. The mistake is at that word or right before it: often a reserved word used as a name, a missing or extra comma, or syntax from another database.

near "order": syntax error

Tested on SQLite 3.51.0 (macOS /usr/bin/sqlite3) · Updated 9 October 2026

What it means

SQLite reads your statement word by word. near "X": syntax error means that X is the first word that can’t continue any valid statement, so SQLite stopped there. It returns SQLITE_ERROR (code 1) and runs nothing.

The word in quotes is where SQLite gave up, not always where the mistake is. Look at it and at the word right before it: in ALTER TABLE users DROP COLUMN IF EXISTS name, SQLite reads IF as the column name and complains about EXISTS.

Two related messages: incomplete input means the statement ended too early (a missing ) or END), and unrecognized token: "…" means a character SQLite doesn’t use at all, such as #, :: or an unclosed quote.

Common causes

  1. A reserved word as a name. order, group, from, index and values can’t be bare table or column names.
  2. A missing or extra comma: between two column definitions, or a trailing comma before FROM or ).
  3. Syntax from another database. MySQL’s AUTO_INCREMENT, MODIFY, UPDATE … JOIN, SHOW TABLES and DESCRIBE; PostgreSQL’s ILIKE, ::text and ADD COLUMN IF NOT EXISTS; SQL Server’s SELECT TOP 5.
  4. A feature newer than your SQLite: RETURNING and DROP COLUMN need 3.35.0, RIGHT and FULL OUTER JOIN need 3.39.0, UPDATE … FROM needs 3.33.0, upsert (ON CONFLICT … DO) needs 3.24.0. Check with SELECT sqlite_version();.
  5. Placeholders that didn’t become values. A %s from another driver’s style, or a ? used for a table or column name: parameters only stand for values.
  6. Two statements without a semicolon between them.

How to fix it

Quote names that are keywords

Use double quotes for identifiers:

SELECT id, "order" FROM users;
CREATE TABLE groups ("group" TEXT);

SQLite also accepts MySQL’s backticks and SQL Server’s square brackets, but double quotes are the standard. Single quotes are for text values.

Check the commas

Read the list right before the quoted word. In CREATE TABLE t1(id INTEGER PRIMARY KEY name TEXT) the error is near "name": the comma after PRIMARY KEY is missing.

Translate syntax from other databases

If you wroteIn SQLite
id INT AUTO_INCREMENT PRIMARY KEYid INTEGER PRIMARY KEY (add AUTOINCREMENT only if ids must never be reused)
SHOW TABLES.tables in the shell, or SELECT name FROM sqlite_schema WHERE type = 'table'
DESCRIBE usersPRAGMA table_info(users)
name ILIKE 'a%'name LIKE 'a%' (case-insensitive for ASCII letters by default)
id::textCAST(id AS TEXT)
SELECT TOP 5 …SELECT … LIMIT 5
UPDATE a JOIN b ON … SET …UPDATE a SET … FROM b WHERE …
ALTER TABLE t ADD COLUMN a …, ADD COLUMN b …one ALTER TABLE t ADD COLUMN per column
ALTER TABLE t MODIFY … / ALTER COLUMN … TYPE …rebuild the table (create, copy, drop, rename)
# comment-- comment

Pass values, not names, as parameters

SELECT * FROM ? fails with near "?". Bind values only; if the table name varies, choose it from a fixed list in your code and put it in the SQL text, quoted.

Upgrade, or rewrite for an older SQLite

If the statement is valid for current SQLite but fails on a server or device, compare SELECT sqlite_version(); there with the versions above. Without RETURNING, run a SELECT after the write; without DROP COLUMN, rebuild the table.

Reproduce it

macOS /usr/bin/sqlite3, SQLite 3.51.0, which prints the position under the statement:

sqlite3 syn.db "SELECT id, order FROM users;"
Error: in prepare, near "order": syntax error
  SELECT id, order FROM users;
             ^--- error here

The shell adds “Error: in prepare,” and the pointer; SQLite’s message is near "order": syntax error. Others from the same session:

Error: in prepare, near "FROM": syntax error
  SELECT id, name, FROM users;
                   ^--- error here
Error: in prepare, near "AUTO_INCREMENT": syntax error
  CREATE TABLE t2(id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
                           error here ---^
Error: in prepare, near "EXISTS": syntax error
  ALTER TABLE users DROP COLUMN IF EXISTS name;
                     error here ---^
Error: in prepare, near "?": syntax error
  SELECT * FROM ?;
                ^--- error here
Error: in prepare, unrecognized token: ":"
  SELECT id::text FROM users;
           ^--- error here

SHOW TABLES, DESCRIBE users, ILIKE, SELECT TOP 5, MODIFY, UPDATE … JOIN and two ADD COLUMN clauses in one statement all failed the same way. SELECT "order" FROM users, RETURNING, RIGHT JOIN and UPDATE … FROM worked on this version.

In Inlet

Inlet’s query editor highlights SQL as you type and completes table and column names from the live schema. When SQLite rejects a statement, Inlet shows the error at the position SQLite reports. With your own Anthropic API key, Ask Claude (⌘L) can fix a failed statement.

Related

Sources