PostgreSQL error: syntax error at or near
ERROR: syntax error at or near "order"
LINE 1: SELECT * FROM order;
^
The parser hit a token it couldn't fit into any valid SQL and stopped. One reading tip changes everything: the caret marks where parsing gave up, which is at or just after the actual mistake — look at the flagged token and the few before it.
What this error means
This is a pure grammar error: the statement never got as far as looking up tables or columns. The quoted token in the message is where the grammar broke. In the sample, order is a reserved word (as in ORDER BY), so a table by that name can't appear unquoted — the parser reads it as the keyword and fails.
Common causes
- Reserved words as identifiers:
order,group,limit,where… as table or column names, unquoted. - MySQL syntax: backticks around identifiers (
`users`),LIMIT 10, 20,AUTO_INCREMENT— all syntax errors in PostgreSQL. - Missing or extra punctuation: a comma before
FROM, unbalanced parentheses, a stray comma after the last column. - Placeholders run literally: executing
WHERE id = $1in psql without providing parameters. - Typographic quotes pasted from chat tools or documents:
’and“aren't SQL quotes.
How to diagnose it
- Read the token in the error and the few tokens before the caret — the mistake lives there.
- If the SQL is generated or templated, print the final statement and run it in psql; syntax errors are much easier to see in the assembled text than in the template.
- Suspicious identifier? Check if it's reserved — quoting it (
"order") as an experiment settles it instantly.
How to fix it
- Reserved word → quote it (
SELECT * FROM "order") — and consider renaming the table; every future query will thank you. - MySQL-isms → translate: double quotes (or nothing) instead of backticks,
LIMIT 20 OFFSET 10,GENERATED ALWAYS AS IDENTITYinstead ofAUTO_INCREMENT. - Smart quotes → retype the quotes in a real editor.
🔍
The next error you'll meet after fixing this one: column does not exist — quoting and case rules for identifiers.
