python - Return existing primary key ID upon constraint failure in sqlite3 -
i have unique
constraint on 2 columns of table in sqlite.
if insert record duplicate on these 2 columns table, exception (sqlite3.integrityerror
).
is possible retrieve primary key id of record upon such violation, without doing additional select
?
if primary key part of unique constraint led violation, have value.
otherwise, 2 columns in unique constraint alternate key table, i.e., can uniquely identify conflicting row.
if need actual primary key, need additional select. (the primary key of existing row not part of exception because never looked @ during insert attempt.)
Comments
Post a Comment