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.

What lands in your log

ERROR: relation "widgets" already exists

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

In 10 seconds

What triggers it
CREATE TABLE with a name that already exists in the current schema.
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.

Fix

What to do right now

Application-level steps for 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);

Verification

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

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops