Reputation: 1
how to use composite Unique using trigger I have one column user_id and service_id i want to restrict duplicate records in user_id according to service_id means ie for service_id=1 all records should be unique in user_id all by trigger
Upvotes: 0
Views: 51
Reputation: 7541
You don't need a trigger for this. A Unique constraint on multiple columns would do it.
ALTER TABLE tab ADD UNIQUE (service_id, user_id);
Docs at: http://www.postgresql.org/docs/current/static/ddl-constraints.html
Upvotes: 1