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?

Rodrigo
  • 3,129
  • 3
  • 33
  • 61
  • @sudo yes did not find that question earlier. Thank you – Rodrigo Feb 28 '18 at 00: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. – sudo Feb 28 '18 at 00:48

0 Answers0