Michael Glaesemann <grzm@xxxxxxxxxxxxxxx> writes: > We have a function which has been throwing a key violation. We're > tracking the purchase history for a limited number of unique items, > and flagging the most recent purchase with purchase_status = 1. Um, the function is ensuring that there is no conflicting row with the same item_id, but the unique constraint is on purchase_id. Plus, since purchase_id is declared PRIMARY KEY, the additional unique constraint is surely a no-op. I think you've anonymized the example into nonsense :-(. regards, tom lane