An exclusion constraint prevents two rows from coexisting when specified expressions compare with operators that all return true. At least one comparison must be false or null. section 2.3.1
For a shopping cart, constrain customer_id with = only among rows whose status is pending. This guarantees each customer has at most one pending order. section 2.6.1
Allow one pending order per customer
ALTER TABLE sales.orders ADD CONSTRAINT one_pending_order_per_customer EXCLUDE USING btree (customer_id WITH =) WHERE (status = 'pending'); The WHERE predicate limits enforcement to pending orders, while the B-tree index supports constraint validation. Updating the pending order to ordered permits a later pending cart. section 2.6.1
