ERROR: column does not exist, though you can see it in the table
ERROR: column "firstname" does not existShort answer
The parser reads your column name differently from how it was stored. Three causes cover most cases: the column was created with a quoted capital letter, a text value was written in double quotes so it is read as a column, or an alias from the SELECT list was used in WHERE.
Fix it fast
1Find out which cause you have
Print the real column names exactly as stored, with their case.
\d users2Match what you see, then jump to its fix
- 1
\d shows firstName, and the query used firstName without quotesThe column was created with a quoted mixed-case nameFix - 2
The name in the message is the value you meant to compare, e.g. column "active"A text value is wrapped in double quotesFix - 3
The missing column is a name you defined with AS in the same queryA SELECT-list alias is used in WHEREFix
- 1
What does the error look like?
ERROR: column "firstname" does not existERROR: column "active" does not existHINT: Perhaps you meant to reference the column "users.firstName".
Cause 1 of 3
The column was created with a quoted mixed-case name
1Check
Unquoted names are folded to lower case, so firstName becomes firstname. Only a double-quoted name keeps its case.
SELECT column_name FROM information_schema.columns WHERE table_name = 'users';2Fix
Quote the column everywhere, or rename it to lower case once.
SELECT "firstName" FROM users;
-- or, once
ALTER TABLE users RENAME COLUMN "firstName" TO first_name;3Verify
The unquoted query works after the rename.
SELECT first_name FROM users LIMIT 1;Confirmed by postgresql.org
Cause 2 of 3
A text value is wrapped in double quotes
1Check
String constants use single quotes. Double quotes mark an identifier, so "active" is read as a column.
SELECT * FROM users WHERE status = "active";2Fix
Use single quotes for values.
SELECT * FROM users WHERE status = 'active';3Verify
The query returns rows instead of the error.
SELECT count(*) FROM users WHERE status = 'active';Confirmed by postgresql.org
Cause 3 of 3
A SELECT-list alias is used in WHERE
1Check
An output column name can be used in ORDER BY and GROUP BY, but not in WHERE or HAVING.
SELECT price * 2 AS double_price FROM products WHERE double_price > 10;2Fix
Repeat the expression in WHERE, or move the query into a subquery.
SELECT price * 2 AS double_price
FROM products
WHERE price * 2 > 10;3Verify
The corrected query runs.
SELECT count(*) FROM products WHERE price * 2 > 10;Confirmed by postgresql.org
How do I stop it coming back?
- Name columns in lower_snake_case and never quote identifiers.
- Configure your ORM to emit lower-case column names.
- Use single quotes for values and double quotes only for identifiers.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Databases
ERROR: relation does not exist for a table that is there
LINE 1: SELECT * FROM users;
The name you typed does not resolve to the table you see.
3 causes, each with a fixDatabases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
DBeaver cannot download the PostgreSQL driver from Maven
The PostgreSQL driver files are missing and the download does not complete
DBeaver downloads the PostgreSQL JDBC driver from a Maven repository the first time you connect.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
Django save fails on PostgreSQL: null value in a column violates a not-null constraint
django.db.utils.IntegrityError: null value in column "price" of relation "shop_product" violates not-null constraint
A model field is NOT NULL in the database unless it has null=True.
3 causes, each with a fixDatabases
Django migration on PostgreSQL stops with 'pending trigger events'
django.db.utils.OperationalError: cannot ALTER TABLE "mytable" because it has pending trigger events
PostgreSQL runs a Django migration in one transaction.
2 causes, each with a fix