pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #7525: Deferred unique index with predicate
2+ messages / 2 participants
[nested] [flat]

* BUG #7525: Deferred unique index with predicate
@ 2012-09-08 12:40  rikard.pavelic@zg.htnet.hr
  0 siblings, 1 reply; 2+ messages in thread

From: rikard.pavelic@zg.htnet.hr @ 2012-09-08 12:40 UTC (permalink / raw)
  To: pgsql-bugs

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/

Can't find it on todo.





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #7525: Deferred unique index with predicate
@ 2012-10-20 18:41  Jeff Davis <pgsql@j-davis.com>
  parent: rikard.pavelic@zg.htnet.hr
  0 siblings, 0 replies; 2+ messages in thread

From: Jeff Davis @ 2012-10-20 18:41 UTC (permalink / raw)
  To: rikard.pavelic@zg.htnet.hr; +Cc: pgsql-bugs

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2012-10-20 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-09-08 12:40 BUG #7525: Deferred unique index with predicate rikard.pavelic@zg.htnet.hr
2012-10-20 18:41 ` Jeff Davis <pgsql@j-davis.com>

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