Re: Insert in table with UNIQUE index - Mailing list pgsql-admin

From bricklen
Subject Re: Insert in table with UNIQUE index
Date
Msg-id CAGrpgQ-Fk7OHjm7E+kcm6QYH5Gz4puqWHDW6Uuj9uUw9-adegg@mail.gmail.com
Whole thread Raw
In response to Insert in table with UNIQUE index  (Artem Tomyuk <admin@leboutique.com>)
List pgsql-admin

On Wed, Jan 27, 2016 at 5:30 AM, Artem Tomyuk <admin@leboutique.com> wrote:
I have a table with unique index with 2 exactly the same rows.
How it can be possible?


CREATE TABLE _inforgchngr6716_test
(
  _nodetref bytea NOT NULL,
  _noderref bytea NOT NULL,
  _messageno numeric(10,0)
)

CREATE UNIQUE INDEX _inforg6716_bynodemsg_rn_test
  ON _inforgchngr6716_test
  USING btree
  (_nodetref, _noderref, _messageno);

In the duplicated entries, are any of the "_messageno" values NULL? If so, that would explain it. NULL is not bound by the constraint, you have a few options: make it NOT NULL, COALESCE() it to a known value, or create a couple partial indexes to enforce the uniqueness.

pgsql-admin by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Insert in table with UNIQUE index
Next
From: Jeff Frost
Date:
Subject: Re: 9.5 repo question