0

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I know this but i have to us it in trigger
I want unique for only for one service constraint on multiple columns will restrict all services

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.