PARTIAL, DEFERRABLE UNIQUE CONSTRAINTS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PARTIAL, DEFERRABLE UNIQUE CONSTRAINTS

Daniel Migowski

Hello,

 

I need to create a deferrable,unique partial constraint (using a WHERE clause) on my table, which in addition should also be deferrable. AFAIK deferrable constraints are just creatable with

 

ALTER TABLE demand ADD CONSTRAINT unique_salesorderitem_id

UNIQUE (salesorderitem_id) DEFERRABLE INITIALLY DEFERRED;

 

but here I miss the WHERE clause. Using the CREATE INDEX notation like this:

 

CREATE UNIQUE INDEX idx_demand_salesorderitem_id_of_parentdemands

    ON demand(salesorderitem_id) WHERE parentdemand_id IS NULL;

 

I cannot specify the deferability (is that a word?). I am Using PostgreSQL 9.1. Is there any way around this?

 

Regards,

Daniel Migowski

Reply | Threaded
Open this post in threaded view
|

Re: PARTIAL, DEFERRABLE UNIQUE CONSTRAINTS

David G Johnston
dmigowski wrote
I need to create a deferrable,unique partial constraint (using a WHERE clause) on my table
I don't know the exact required syntax but the description of the "EXCLUDE" clause to "CREATE TABLE" implies that it can be used to accomplish what you desire.

Not tested but something like:

EXCLUDE USING btree ( col WITH = ) WHERE ... DEFERRABLE INITIALLY IMMEDIATE

http://www.postgresql.org/docs/9.1/static/sql-createtable.html

While the documentation says that using btree with EXCLUDE is uncommon this does seem to be a mandatory exception.

David J.
 


Reply | Threaded
Open this post in threaded view
|

Re: PARTIAL, DEFERRABLE UNIQUE CONSTRAINTS

Daniel Migowski
Works like a charm! Thank you very much, PostgreSQL really is an awesome database, and so is the community.


-----Urspr√ľngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von David G Johnston
Gesendet: Mittwoch, 10. September 2014 15:45
An: [hidden email]
Betreff: Re: [GENERAL] PARTIAL, DEFERRABLE UNIQUE CONSTRAINTS

dmigowski wrote
> I need to create a deferrable,unique partial constraint (using a WHERE
> clause) on my table

I don't know the exact required syntax but the description of the "EXCLUDE"
clause to "CREATE TABLE" implies that it can be used to accomplish what you desire.

Not tested but something like:

EXCLUDE USING btree ( col WITH = ) WHERE ... DEFERRABLE INITIALLY IMMEDIATE

http://www.postgresql.org/docs/9.1/static/sql-createtable.html

While the documentation says that using btree with EXCLUDE is uncommon this does seem to be a mandatory exception.

David J.
 






--
View this message in context: http://postgresql.1045698.n5.nabble.com/PARTIAL-DEFERRABLE-UNIQUE-CONSTRAINTS-tp5818441p5818445.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


--
Sent via pgsql-general mailing list ([hidden email]) To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general