[PostgreSQL] ERROR: Cannot insert a duplicate key into unique index

Tadashi Shigeoka ·  Tue, March 27, 2012

In PostgreSQL, when inserting a new record, I encountered the following error:

ERROR: Cannot insert a duplicate key into unique index tbl_xxxx_pkey

The cause was that the column xxxx_pkey of a record that already exists in the DB was violating the UNIQUE constraint.

UNIQUE 制約

[ CONSTRAINT name ] UNIQUE

入力

CONSTRAINT name 制約に付与する任意の名前。

出力

status ERROR: Cannot insert a duplicate key into a unique index. このエラーは、列に重複する値を挿入しようとした、 その実行時に起こります。

・Source: CREATE TABLE

That’s all from the Gemba.

【Reference】

ポストグレスSQLメモ(Hishidama’s PostgreSQL SQL Memo)