SQL error
unterminated quoted string at or near … / unrecognized token
Updated · Tested on PostgreSQL 18.6 and SQLite 3.54.1 (results generated , re-checked on every release)
Short answer
A text value opens with ' and never closes, so the rest of the query is read as text. Add the closing quote. To put an apostrophe inside text, write it twice: 'Rocket''s best'.
The exact messages
- PostgreSQLERROR: unterminated quoted string at or near "'Austin;"
- SQLiteunrecognized token: "'Austin;"
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.
ERROR: unterminated quoted string at or near "'Austin;"
LINE 2: WHERE city = 'Austin;
^SQLite 3.54.1 reports the same mistake as unrecognized token: "'Austin;", with no line number: look for the word or column it names.
Why it happens
A missing closing quote
WHERE city = 'Austin; – the semicolon became part of the text. The message quotes where the text started.
An apostrophe inside the text
'O'Brien' ends the text after O. Double the apostrophe, 'O''Brien'; that's the SQL way to write a quote inside quotes in both databases.
Curly quotes from a document
Copying SQL from a word processor turns ' into ‘ ’, which SQL doesn't treat as quotes. Retype them in the editor.
Reproduce it, then fix it
Both queries run on a real database in your browser. Switch dialects to compare.
SELECT name FROM customers
WHERE city = 'Austin;SELECT name FROM customers
WHERE city = 'Austin';The closing quote ends the text, so the semicolon ends the query again.
The fix returns, PostgreSQL: 3 rows
| name |
|---|
| Maya Ortiz |
| Priya Nair |
| Lena Fischer |
The fix returns, SQLite: 3 rows
| name |
|---|
| Maya Ortiz |
| Priya Nair |
| Lena Fischer |
Experiment with it: PostgreSQL playground·SQLite playground
Another fix
Two apostrophes in a row inside quotes stand for one apostrophe.
SELECT name, 'Rocket''s regular' AS label
FROM customers
WHERE city = 'Austin';Returns, PostgreSQL: 3 rows
| name | label |
|---|---|
| Maya Ortiz | Rocket's regular |
| Priya Nair | Rocket's regular |
| Lena Fischer | Rocket's regular |
Returns, SQLite: 3 rows
| name | label |
|---|---|
| Maya Ortiz | Rocket's regular |
| Priya Nair | Rocket's regular |
| Lena Fischer | Rocket's regular |
Official documentation
Stop hitting this error
Practise the concept behind it in a five-minute lesson, or read the full guide: SQL WHERE clause: filtering rows.