0

I have a what some might call a pivot table for a many to many relationship. Here are the tables.

users:
 - id
 - name

excursions:
 - id
 - name

excursion_user:
 - user_id
 - excursion_id

I want to add a unique constraint to only allow 1 excursion per user. So the user_id excursion_id pair can only exist once in the table. How would I go about writing this constraint?

2
  • @sudo yes did not find that question earlier. Thank you Commented Feb 28, 2018 at 0:42
  • No problem. PostgreSQL also has nice official documentation you could check if you don't want to risk getting out of date information from older answers. In this case, it's the same, but there are lots of new features for more advanced things like upserts. Commented Feb 28, 2018 at 0:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.