Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

A table with capital letters cannot be found in PostgreSQL

ErrorWhy PostgreSQL does not like uppercase table names

Short answer

PostgreSQL folds unquoted names to lower case. A table created as "Users" with double quotes keeps its capital letter, so a query for Users or users looks for a different name. Quote the name exactly every time, or rename the table and columns to lower case so no quotes are needed.

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

Fix it fast

  1. 1Find out which cause you have

    List tables and see how the name is spelled. A capital letter in the list means the name was created quoted.

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

    1. 1\dt shows Users but SELECT * FROM Users failsThe table was created with a quoted mixed-case nameFix
    2. 2The table is found but a column such as firstName failsColumns were created quoted as wellFix
    3. 3Every query and tool must carry quotesYou want to stop quoting for goodFix

What does the error look like?

  • Why PostgreSQL does not like uppercase table names
  • A query works only when the table name is in double quotes

Cause 1 of 3

The table was created with a quoted mixed-case name

1Check

Quoting an identifier makes it case-sensitive, while unquoted names are folded to lower case. FOO, foo and "foo" are the same name; "Foo" and "FOO" are different ones.

\dt

2Fix

Use the double-quoted name exactly as it was created.

SELECT * FROM "Users";

3Verify

The query returns rows.

SELECT count(*) FROM "Users";

Confirmed by postgresql.org

Did this fix it?

Cause 2 of 3

Columns were created quoted as well

1Check

The same folding rule applies to column names, so a column created as "firstName" must be quoted in every query.

\d "Users"

2Fix

Quote the column in each query, or rename it to a lower-case name.

SELECT "firstName" FROM "Users";

3Verify

The column is returned.

SELECT "firstName" FROM "Users" LIMIT 1;

Confirmed by postgresql.org

Did this fix it?

Cause 3 of 3

You want to stop quoting for good

1Check

The manual advises to always quote a particular name or never quote it. Renaming to lower case lets plain names work.

\dt

2Fix

Rename the table and columns once.

ALTER TABLE "Users" RENAME TO users;
ALTER TABLE users RENAME COLUMN "firstName" TO first_name;

3Verify

An unquoted query now works.

SELECT first_name FROM users LIMIT 1;

Confirmed by postgresql.org

Did this fix it?

How do I stop it coming back?

  • Create tables and columns in lower case with underscores, unquoted.
  • Check what names your ORM or migration tool generates; some quote them.
  • Never mix quoted and unquoted styles in one database.

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.