How to get the exact value that caused the Uniqueviolation exception?
The illustrative code is:
try:
cur.execute("INSERT INTO test (num) VALUES (1), (2), (3), (3);")
conn.commit()
except psycopg.errors.UniqueViolation as err:
print("Failed to insert non-unique number: {}".format(???))
conn.rollback()
so the question is how to print the number "3"? Does the psycopg.errors.UniqueViolation
contain the value that violated the constraint at all?
In the real code the values are dynamic. I log the rolled back transaction, but I'd like to also identify the offending number in the list, and ideally repeat the transaction without the duplicate.