Postgresql unique index: only one date for one foreign key

Create a conditional unique index:

CREATE UNIQUE INDEX u_productid_end_date_not_null
ON foo(product_Id) 
WHERE end_date IS NOT NULL; -- this one will do the trick

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top