From: Emre Hasegeli <emre.hasegeli@tart.com.tr>
To: pgsql-admin@postgresql.org, "Technical Doubts" <online.technicaldoubts@gmail.com>
Subject: Re: Composite Unique Key - Doubt
Date: Thu, 20 Jun 2013 11:10:11 +0300
Message-ID: <op.wyywy9hik2xoe5@hasegeli.local> (raw)
In-Reply-To: <CAJyuQsHW0paQSWuy0GhzotvnrVxJf0vZNBWPqeZ8xGz8jo+Q7w@mail.gmail.com>
References: <CAJyuQsHW0paQSWuy0GhzotvnrVxJf0vZNBWPqeZ8xGz8jo+Q7w@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>
On Thu, 20 Jun 2013 10:42:37 +0300, Technical Doubts
<online.technicaldoubts@gmail.com> wrote:
> Team,
>
> Am using Postgres 9.2
>
> I am having a table
>
> technologies
> (
> technologyid bigint,
> status character(1),
> implementeddate date
> *CONSTRAINT technologies_uq UNIQUE (technologyid, status,
> implementeddate)*
> )
>
> entering data as
>
> insert into technologies (technologyid,status,implementeddate)
> values
> (123,'P',null),
> (123,'P',null);
>
> 2 rows affected.
>
> table accepting duplicate values in spite of composite unique
> constraint..
> where I am doing wrong?
You are not doing anything wrong. From documentation:
> In general, a unique constraint is violated when there is more than one
> row in the table where the values of all of the columns > included in
> the constraint are equal. However, two null values are not considered
> equal in this comparison. That means even in the presence of a unique
> constraint it is possible to store duplicate rows that contain a null
> value in at least one of the constrained columns. This behavior conforms
> to the SQL standard, but we have heard that other SQL databases might
> not follow this rule. So be careful when developing applications that
> are intended to be portable.
Try not null constraints or functional unique indexes.
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: emre.hasegeli@tart.com.tr, online.technicaldoubts@gmail.com
Subject: Re: Composite Unique Key - Doubt
In-Reply-To: <op.wyywy9hik2xoe5@hasegeli.local>
References: <CAJyuQsHW0paQSWuy0GhzotvnrVxJf0vZNBWPqeZ8xGz8jo+Q7w@mail.gmail.com> <op.wyywy9hik2xoe5@hasegeli.local>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox