Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLITE3 Error: "SQLITE_RANGE: column index out of range"

Tags:

sql

sqlite

I'm trying to search for a user by a string so kind of like autocompletion

Here's my SQL:

SELECT * FROM users WHERE username LIKE "%?%" LIMIT 25;

And it gives me this error: SQLITE_RANGE: column index out of range

I looked into a bunch of github issues but couldn't find any that works for me.
In the SQLite CLI it works, so I have no idea why it wouldn't work here.

like image 704
chomeable Avatar asked Oct 17 '25 19:10

chomeable


1 Answers

A ? inside a string like "%?%" is not considered as a placeholder for the parameter that you pass, which throws the error that you get because the parameter has no where to be placed in the statement.

Use concatenation of the ? with the wildcards:

SELECT * FROM users WHERE username LIKE "%" || ? || "%" LIMIT 25;
like image 114
forpas Avatar answered Oct 19 '25 11:10

forpas