SQLSTATE 42701 ERROR Class 42: Syntax Error or Access Rule Violation

duplicate_column column “…” of relation “…” already exists — 42701

PostgreSQL error "column "…" of relation "…" already exists" (SQLSTATE 42701): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

An ALTER TABLE … ADD COLUMN (or a CREATE TABLE) tried to add a column whose name already exists on that table. PostgreSQL reports SQLSTATE 42701 (duplicate_column).

  • Most common on non-idempotent ADD COLUMN migrations.
  • The message names both the column and the relation.
  • The table is left unchanged.

What the server log shows

ERROR:  column "status" of relation "orders" already exists

Why PostgreSQL raises this — what the manual says

the ALTER TABLE reference (ADD COLUMN):

“This form adds a new column to the table, using the same syntax as CREATE TABLE.”

Column names are unique within a table. ADD COLUMN checks pg_attribute for an existing live column of the same name and raises 42701 if found, leaving the table untouched.

Common causes

  • A migration that already ran being applied again.
  • Two migrations adding the same column.
  • The column was added manually outside the migration tool.

How to fix it

  1. Use ALTER TABLE orders ADD COLUMN IF NOT EXISTS status text;.
  2. Check the current columns with \d orders before adding.
  3. tuple/" title="Tuple">Record applied migrations so they do not re-run.

Diagnostic query

-- Does the column already exist on the table?
SELECT attname, atttypid::regtype AS type
FROM pg_attribute
WHERE attrelid = 'orders'::regclass AND attname = 'status' AND NOT attisdropped;

Related & next steps

Reference: PostgreSQL 18 — ALTER TABLE.

Was this helpful?