Likes table for a post - how to identify if the post was already liked by that user?

Viewed 36

My likes table is a intermediat table in a many-to-many relationship between posts and users. It has the following fields:

id
post_id
user_id

In my mind, the cleanest way to ensure there are no duplicates is to make the ID a concatenation of post_id and user_id. If this is the best way, the question is:

In postgres, how can I make a field have a default value equal to the concatenation of other two fields?

0 Answers
Related