Re: Insert in table with UNIQUE index

From: bricklen <bricklen(at)gmail(dot)com>
To: Artem Tomyuk <admin(at)leboutique(dot)com>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Insert in table with UNIQUE index
Date: 2016-01-27 16:06:02
Message-ID: CAGrpgQ-Fk7OHjm7E+kcm6QYH5Gz4puqWHDW6Uuj9uUw9-adegg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Wed, Jan 27, 2016 at 5:30 AM, Artem Tomyuk <admin(at)leboutique(dot)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.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jeff Frost 2016-01-27 16:48:46 Re: 9.5 repo question
Previous Message David G. Johnston 2016-01-27 15:49:43 Re: Insert in table with UNIQUE index