SQLSTATE 42P07Severity lowLab verified

Incident brief

Relation already exists

A CREATE TABLE named a relation that already exists. PostgreSQL refused to create a second object under the same name instead of silently overwriting it.

Reproduced on PostgreSQL 16.14Verified 2026-07-15 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Relation already exists
What triggers it
CREATE TABLE with a name that already exists in the current schema.
The fix
Use CREATE TABLE IF NOT EXISTS if the script is meant to be safely re-runnable.
Proof
Reproduced on PostgreSQL 16.14 → Creating a table with a name that already existed was rejected with SQLSTATE 42P07. The table was confirmed unchanged afterward.

The fix

What to do right now

The immediate, application-level response to this error.

  • Use CREATE TABLE IF NOT EXISTS if the script is meant to be safely re-runnable.
  • Otherwise, rename the new table or drop the old one first, deliberately.
  • Don't assume IF NOT EXISTS updates an existing table's columns — see the premium test for what it actually does.
Fix — SQL
CREATE TABLE IF NOT EXISTS inventory.widgets (id serial PRIMARY KEY, note text);

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-15 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed