chomeable
chomeable

Reputation: 51

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

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.

Upvotes: 4

Views: 1806

Answers (1)

forpas
forpas

Reputation: 164089

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;

Upvotes: 5

Related Questions