Applications and operations

Fix “relation does not exist”

Check the current database, schema path, migrations, and PostgreSQL identifier folding before changing a query.

8 minute lesson

~~~

PostgreSQL says “relation does not exist” when it cannot resolve the table name in the current connection.

Check the connection and visible tables first:

SELECT current_database(), current_schema();
SHOW search_path;
\dt *.*

If app.notes exists but notes fails, fix the search_path or qualify the table as app.notes. If the table is absent, run the expected migrations against this database.

PostgreSQL folds unquoted identifiers to lowercase. CREATE TABLE Notes creates notes, while CREATE TABLE "Notes" creates a case-sensitive name that always needs quotes.

My advice is to use lowercase unquoted names. Do not add quotes until you know the table was created with a quoted mixed-case name.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →