i am running a query in mysql insert ignore into........ using Python
after running the query I want to know the primary key of the row. I know there is the query
SELECT LAST_INSERT_ID();
but i’m not sure if it will work with insert ignore
what is the best way to do this?
The documentation for
LAST_INSERT_ID()says:Knowing this, you can make this a multi-step process:
Example with U.S. states:
Now, inserting a new row:
Inserting a row which will be ignored:
Alternately, there is a possible workaround to do this in one step – use
REPLACE INTOinstead ofINSERT IGNORE INTO– the syntax is very similar. Note however that there are side effects with this approach – these may or may not be important to you:INSERT IGNOREkeeps the old row data,REPLACEreplaces it with new row data