Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

ERROR: column does not exist, though you can see it in the table

ErrorERROR: column "firstname" does not exist

Short 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.

  • Applies to PostgreSQL 16, PostgreSQL 17, psql 17
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the real column names exactly as stored, with their case.

    \d users
  2. 2Match what you see, then jump to its fix

    1. 1\d shows firstName, and the query used firstName without quotesThe column was created with a quoted mixed-case nameFix
    2. 2The name in the message is the value you meant to compare, e.g. column "active"A text value is wrapped in double quotesFix
    3. 3The missing column is a name you defined with AS in the same queryA SELECT-list alias is used in WHEREFix

What does the error look like?

  • ERROR: column "firstname" does not exist
  • ERROR: column "active" does not exist
  • HINT: 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

Did this fix it?

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

Did this fix it?

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

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.