Answer the question
In order to leave comments, you need to log in
PostgreSQL: How to disable duplicate?
How can I prevent a duplicate record if it already exists in the table?
Tried like this:
cur.execute("INSERT INTO likes (postid, like_one, like_two) VALUES (%s, %s, %s) ON CONFLICT (postid)", (postid, 0, 0))
Answer the question
In order to leave comments, you need to log in
You can create a unique index for all 3 fields, or an insert trigger.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question