From: | Jeff Davis <pgsql(at)j-davis(dot)com> |
---|---|
To: | rikard(dot)pavelic(at)zg(dot)htnet(dot)hr |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #7525: Deferred unique index with predicate |
Date: | 2012-10-20 18:41:43 |
Message-ID: | 1350758503.14401.18.camel@jdavis |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Sat, 2012-09-08 at 12:40 +0000, rikard(dot)pavelic(at)zg(dot)htnet(dot)hr wrote:
> The following bug has been logged on the website:
>
> Bug reference: 7525
> Logged by: Rikard Pavelic
> Email address: rikard(dot)pavelic(at)zg(dot)htnet(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | obasan | 2012-10-22 09:16:06 | BUG #7616: -E parameter doesn't override template values. |
Previous Message | Tom Lane | 2012-10-20 16:46:34 | Re: pgbench % output incorrect with large scales |