From: Jeff Davis <pgsql@j-davis.com>
To: rikard.pavelic@zg.htnet.hr
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7525: Deferred unique index with predicate
Date: Sat, 20 Oct 2012 11:41:43 -0700
Message-ID: <1350758503.14401.18.camel@jdavis> (raw)
In-Reply-To: <E1TAKKS-00040l-0A@wrigleys.postgresql.org>
References: <E1TAKKS-00040l-0A@wrigleys.postgresql.org>
On Sat, 2012-09-08 at 12:40 +0000, rikard.pavelic@zg.htnet.hr wrote:
> The following bug has been logged on the website:
>
> Bug reference: 7525
> Logged by: Rikard Pavelic
> Email address: rikard.pavelic@zg.htnet.hr
> PostgreSQL version: 9.1.2
> Operating system: Windows 7
> Description:
>
> Is there a way in Postgres to create a unique constraint with predicate or
> an unique index which is deferred?
>
> Depesz said not yet.
> http://www.depesz.com/2009/08/11/waiting-for-8-5-deferrable-uniqueness/
Both features exist.
http://www.postgresql.org/docs/9.2/static/sql-createtable.html
CREATE TABLE xyz(i int, j int, unique (i) deferrable);
To create a unique index with a predicate, do:
CREATE UNIQUE INDEX xyz_uniq_idx ON xyz(j) WHERE j > 10;
However, it can't both be deferrable and have a predicate. In order to
do that, you need to use an exclusion constraint:
http://www.postgresql.org/docs/9.2/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
To make it equivalent to UNIQUE, set all operators to "=", e.g.:
CREATE TABLE xyz(i int, exclude (i WITH =) where (i > 10) deferrable);
Regards,
Jeff Davis
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-bugs@postgresql.org
Cc: pgsql@j-davis.com, rikard.pavelic@zg.htnet.hr
Subject: Re: BUG #7525: Deferred unique index with predicate
In-Reply-To: <1350758503.14401.18.camel@jdavis>
References: <E1TAKKS-00040l-0A@wrigleys.postgresql.org> <1350758503.14401.18.camel@jdavis>
* 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