Upsert with multiply onConflict #18503
Unanswered
Minhnhat0408
asked this question in
Questions
Replies: 1 comment 4 replies
|
I believe both columns have to be part of a unique constraint, not each separately. ALTER TABLE table_name
ADD CONSTRAINT constraint_name
UNIQUE(column1,column2); |
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
So I have a reactions table like this

And i want to upsert if user click 'up' or 'down' (type) each reactions can should have at least post_id or user_id different from each other (each user can only have on react on the post)

I come across the solution with upsert (insert when not exist update when existed) with onConflict ) and a stackoverflow post about multiple constrant for it:
but for my case it doesn't work even if I had already set post_id and user_id tobe unique in the table. It still give me the error:"there is no unique or exclusion constraint matching the ON CONFLICT specification"

hope you guys can help me did I do anything wrong
All reactions