pgref.dev/sqlite/errors/SQLITE_RANGE
SQLITE_RANGEERRORTier 2 — Caution⚠️ MEDIUM confidence

Bind or column index out of range

Category: API MisuseVersions: 3.0+

🔴 Production Risk Error

Medium — causes data to not be bound, leading to unexpected NULL values or errors.

What this means

SQLITE_RANGE (25) is returned when the second argument to sqlite3_bind_*() or sqlite3_column_*() is out of range. Column and parameter indices are 1-based in the C API.

Why it happens

  1. 1Passing a parameter index of 0 or greater than the number of bind parameters.
  2. 2Accessing a column index beyond the number of columns in the result set.
  3. 3Off-by-one error in C extension code — SQLite bind indices start at 1, not 0.

How to reproduce

sqlite3_bind_*() and sqlite3_column_*() calls with invalid indices.

trigger — this will ERROR
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE t(a,b)')
conn.execute('INSERT INTO t VALUES(?,?)', (1, 2))
cur = conn.execute('SELECT a FROM t')
row = cur.fetchone()
# Python driver abstracts index; in C API:
# sqlite3_column_int(stmt, 5) on a 1-column resultSQLITE_RANGE
In C: SQLITE_RANGE; in Python driver: IndexError or similar.

Fix 1

Why this works

In C code, ensure bind indices are in the range [1, sqlite3_bind_parameter_count()].

Fix 2

Why this works

Ensure column indices are in the range [0, sqlite3_column_count()-1] for sqlite3_column_*().

Fix 3

Why this works

Use sqlite3_bind_parameter_name() to verify named parameters.

What not to do

Why it's wrong:

Sources

📚 Official docs: https://www.sqlite.org/rescode.html#range

🔧 Source ref: sqlite3.h — SQLITE_RANGE = 25

📖 Further reading: sqlite3_bind_*()

Confidence assessment

⚠️ MEDIUM confidence

Stable.

See also

📄 Reference pages

sqlite3_bind_*
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →