Free: 4 trials of 20 minutes, no cardStart free

Craftstack Academy
SQL

PostgreSQL ERROR: column does not exist, and how to fix it

· 8 min read

You look for one visitor in the museum log. The column name exists, the value Alex exists, and PostgreSQL says a column called Alex doesn't:

Error (PostgreSQL)
ERROR:  column "Alex" does not exist
LINE 1: SELECT * FROM visitors WHERE name = "Alex";
                                            ^

ERROR: column "x" does not exist means PostgreSQL read something in your query as a column name, and the table has no column with that name. Look at the name in the quotes: it's exactly what PostgreSQL looked for. In this example, it's Alex, a value you meant as text, because it was in double quotes, and in PostgreSQL double quotes mean "this is a name". The fix is single quotes. That's the most common cause, but there are four more, including capital letters, which work differently in PostgreSQL than in most other databases. This article explains each, with the exact output.

Try it yourself

Run this in psql, pgAdmin or any PostgreSQL tool:

setup.sql
CREATE TABLE visitors (id serial PRIMARY KEY, name text, room text, visit_date date);
INSERT INTO visitors (name, room, visit_date) VALUES
  ('Alex', 'Vault', '2026-12-01'),
  ('Sam', 'Lobby', '2026-12-02');

Then:

sql
SELECT * FROM visitors WHERE name = "Alex";

You'll get the error above.

What the error means

Read it in parts:

  • ERROR: column "Alex" does not exist: the name PostgreSQL looked for, exactly as it understood it, including capital letters.
  • LINE 1: and the ^: the query and the exact spot.
  • HINT: (when there is one): PostgreSQL's suggestion. Read it. It's often the answer.

Then ask: did I mean this as a column name at all? If not, it's a quoting problem. If yes, it's a spelling, capitals or alias problem.

Cause 1: double quotes around text

In SQL, the two kinds of quotes mean different things:

  • Single quotes 'Alex' are text, a value.
  • Double quotes "Alex" are a name, of a column or a table.

So name = "Alex" asks PostgreSQL to compare the name column with a column called Alex. The fix:

sql
SELECT name FROM visitors WHERE name = 'Alex';
Result
 name
------
 Alex
(1 row)

If you come from Python or JavaScript, where both quote types make strings, this catches you every time at first. In SQL, text is always single quotes.

Text with no quotes at all

The same error appears when you forget the quotes completely:

sql
UPDATE visitors SET room = Vault WHERE name = 'Sam';
Error (PostgreSQL)
ERROR:  column "vault" does not exist
LINE 1: UPDATE visitors SET room = Vault WHERE name = 'Sam';
                                   ^

Without quotes, Vault is read as a name. And notice the message says "vault" in lowercase, not Vault. That's the next cause.

Cause 2: capital letters in names

PostgreSQL turns unquoted names into lowercase. SELECT Name FROM Visitors is read as SELECT name FROM visitors. Usually that's harmless, because tables created without quotes are lowercase too.

The trouble starts when a table was created with double quotes and capital letters, which often happens when a tool or a framework creates the tables for you:

sql
CREATE TABLE "Orders" ("OrderId" int, "CustomerName" text);
SELECT CustomerName FROM "Orders";
Error (PostgreSQL)
ERROR:  column "customername" does not exist
LINE 1: SELECT CustomerName FROM "Orders";
               ^
HINT:  Perhaps you meant to reference the column "Orders.CustomerName".

PostgreSQL lowercased CustomerName to customername, but the real column is CustomerName, with capitals, because it was created in quotes. The HINT tells you exactly that. Two fixes:

  • Quote it exactly as created: SELECT "CustomerName" FROM "Orders"; works.
  • Better, in your own tables: use lowercase names with underscores, like customer_name, and never quote them. Then capitals never matter.

The table name has the same rule: SELECT customername FROM Orders fails with relation "orders" does not exist, because the table is "Orders" with a capital O. For that message, see SQLite: no such table, which also covers PostgreSQL's version.

Cause 3: a typo in the column name

sql
SELECT nmae FROM visitors;
Error (PostgreSQL)
ERROR:  column "nmae" does not exist
LINE 1: SELECT nmae FROM visitors;
               ^
HINT:  Perhaps you meant to reference the column "visitors.name".

PostgreSQL suggests the closest existing column. It works with aliases too: SELECT v.nam FROM visitors v gave HINT: Perhaps you meant to reference the column "v.name".

To see every column of a table in psql, type \d visitors.

Cause 4: an alias used in WHERE

You can rename a column in the result with AS, but that new name doesn't exist yet when WHERE runs:

sql
SELECT name, room AS place FROM visitors WHERE place = 'Vault';
Error (PostgreSQL)
ERROR:  column "place" does not exist
LINE 1: SELECT name, room AS place FROM visitors WHERE place = 'Vaul...
                                                       ^

The reason is the order in which SQL works: FROM and WHERE run before SELECT gives columns their new names. So in WHERE, use the original column: WHERE room = 'Vault'.

ORDER BY runs last, so the alias works there: ORDER BY place ran without error in our test.

The same in HAVING

sql
SELECT name, COUNT(*) AS visits FROM visitors GROUP BY name HAVING visits > 0;
Error (PostgreSQL)
ERROR:  column "visits" does not exist
LINE 1: ...T(*) AS visits FROM visitors GROUP BY name HAVING visits > 0...
                                                             ^

In PostgreSQL, HAVING can't use the alias either. Repeat the expression: HAVING COUNT(*) > 0. (SQLite accepts the alias here, which is one of several small differences explained in our GROUP BY errors article.)

If you really want to filter on the new name, wrap the query, so the alias exists in the outer one:

sql
SELECT * FROM (SELECT name, room AS place FROM visitors) v WHERE place = 'Vault';

Cause 5: a wrong column in INSERT or UPDATE

In an INSERT, the message names the table too:

sql
INSERT INTO visitors (name, rooms) VALUES ('Mia', 'Vault');
Error (PostgreSQL)
ERROR:  column "rooms" of relation "visitors" does not exist
LINE 1: INSERT INTO visitors (name, rooms) VALUES ('Mia', 'Vault');
                                    ^

rooms versus room: singular and plural mix-ups are the most common column typos.

The same error in SQLite and MySQL

The idea is the same in every database, with different words:

  • SQLite: no such column: Alex. See SQLite: no such column.
  • MySQL: Unknown column 'Alex' in 'where clause' (or in 'field list').

One difference matters: SQLite and MySQL don't lowercase names the way PostgreSQL does, so cause 2 is mostly a PostgreSQL problem.

Errors that look alike

  • relation "x" does not exist: the table isn't found, not the column.
  • column reference "id" is ambiguous: the column exists in two joined tables. See ambiguous column name.
  • must appear in the GROUP BY clause: the column exists, but can't be used that way in a grouped query. See GROUP BY errors.

Wrong fixes that don't help

  • Putting double quotes around everything. Then every name must match its exact case, and text values become column names.
  • Renaming your column to match the typo. Fix the query instead.
  • Creating tables with capital letters in quotes. It works, but every query afterwards needs the quotes too.

A debugging walkthrough

  1. Read the name in the quotes. Is it a value you meant as text? Use single quotes.
  2. Is it lowercase while your column has capitals? The table was created with quoted names: quote the column exactly, or rename the column to lowercase.
  3. Read the HINT. It often names the right column.
  4. Is it an alias from SELECT? Use the original column in WHERE and HAVING.
  5. List the columns with \d tablename in psql, and compare letter by letter.

Practice

Which of these work, with the visitors table above?

  1. SELECT * FROM visitors WHERE room = 'Vault';
  2. SELECT * FROM Visitors WHERE Room = 'Vault';
  3. SELECT * FROM visitors WHERE room = "Vault";

Answers. (1) Works. (2) Works too: PostgreSQL lowercases Visitors and Room, and the table and column were created in lowercase. (3) column "Vault" does not exist: double quotes make it a name.

Frequently asked questions

What does "column does not exist" mean in PostgreSQL?

PostgreSQL read something in your query as a column name, and the table has no column with that name. Check quotes, capitals, aliases and spelling.

Why does PostgreSQL say a column doesn't exist when it does?

Usually because the column was created with capital letters in double quotes, and your query doesn't quote it. PostgreSQL lowercases unquoted names.

What's the difference between single and double quotes in PostgreSQL?

Single quotes are text values. Double quotes are names of columns and tables, and keep their exact capital letters.

Can I use a column alias in WHERE?

No. WHERE runs before the aliases from SELECT exist. Use the original column, or wrap the query in a subquery.

How do I see the columns of a table?

In psql, \d tablename. In any tool, SELECT column_name FROM information_schema.columns WHERE table_name = 'visitors';.

A quick checklist

  1. Text in single quotes, never double.
  2. Read the name in the error: lowercase where you expected capitals?
  3. Read the HINT.
  4. No SELECT aliases in WHERE or HAVING.
  5. Name your own columns in lowercase with underscores.

For a method that works on any error, read how to read an error message. The PostgreSQL documentation explains identifiers and quoting.

1 beginner error a week

One common error, what it means and how to fix it, in a short email. Free, and you can unsubscribe in any email.

SQL

SQL error: ambiguous column name, and how to fix it

Why SQLite says ambiguous column name: id and PostgreSQL says column reference "id" is ambiguous after a JOIN, and how table aliases fix it in SELECT, WHERE, ORDER BY and GROUP BY. With real output.

Error explained · · 9 min read

SQL

SQLite: UNIQUE constraint failed, and how to fix it

Why SQLite says UNIQUE constraint failed: users.email (sqlite3.IntegrityError): a duplicate value, a primary key you set by hand, a script run twice. How to find the duplicate and fix it, with real output.

Error explained · · 9 min read

SQL

SQLite error: no such table, and how to fix it

Why SQLite says no such table (sqlite3.OperationalError: no such table): a typo, a table never created, or the wrong database file, often a new empty one. How to check and fix each, with real output.

Error explained · · 9 min read

Learn by writing the code yourself.

Twenty minutes with the tutor, right in your browser. No card, nothing to install.

Start the free trial
A session: the tutor's chat on the left, the code editor with a Java program and its output on the right