EMZETT.
Login

Error 23505: unique violation (PostgreSQL)

In short: A record violates a uniqueness rule (UNIQUE or primary key).

In more detail: PostgreSQL code 23505.

In Depth

Possible causes

  • Duplicate value in a unique column.
  • Sequence not adjusted after import.

Solutions

  1. Check for existing values beforehand.
  2. Use INSERT ... ON CONFLICT.
  3. Reset the sequence.

See also: PostgreSQL, SQL, CRUD