SQL error
wrong number of arguments to function substr() (SQLite)
Updated · Tested on PostgreSQL 18.6 and SQLite 3.54.1 (results generated , re-checked on every release)
Short answer
The function was called with too few or too many arguments. substr needs at least a string and a start position: substr(name, 1, 3). SQLite says so directly; PostgreSQL reports that no function with that argument list exists.
The exact messages
- PostgreSQLERROR: function substr(text) does not exist
- SQLitewrong number of arguments to function substr()
How to read this message
This is what PostgreSQL 18.6 prints for the broken query below, the way psql shows it. LINE gives the line it was reading when it gave up, and the ^ marks the exact spot. HINT is PostgreSQL's own suggestion, and it's usually worth following.
ERROR: function substr(text) does not exist
LINE 1: SELECT substr(name) AS short
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.SQLite 3.54.1 reports the same mistake as wrong number of arguments to function substr(), with no line number: look for the word or column it names.
Why it happens
A missing argument
substr(name), round(), replace(x, 'a'): each needs more.
An extra argument
round(x, 1, 2) or a function from another database with a different signature.
A misplaced bracket
substr(name, 1), 3) closes the call early, leaving the 3 outside.
Reproduce it, then fix it
Both queries run on a real database in your browser. Switch dialects to compare.
SELECT substr(name) AS short
FROM pets;SELECT substr(name, 1, 3) AS short
FROM pets
ORDER BY id
LIMIT 5;Text, start position and length: the first three letters.
The fix returns, PostgreSQL: 5 rows
| short |
|---|
| Bis |
| Moc |
| Pic |
| Lun |
| Waf |
The fix returns, SQLite: 5 rows
| short |
|---|
| Bis |
| Moc |
| Pic |
| Lun |
| Waf |
Experiment with it: PostgreSQL playground·SQLite playground
Other forms of this mistake
Each one was run when this page was built; the result is what the engine really does.
SELECT round(weight_kg, 1, 2) FROM pets;SQLitewrong number of arguments to function round()
Too many arguments get the same message.
SELECT round(weight_kg, 1, 2) FROM pets;PostgreSQLERROR: function round(numeric, integer, integer) does not exist
PostgreSQL lists the argument types it was given.
Official documentation
Stop hitting this error
Practise the concept behind it in a five-minute lesson, or read the full guide: SQL string functions.