Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm currently using _mysql library in python.

it uses pkey(int, auto increment) value that's created when inserting data using function conn.insert_id()

This is how the query is made. INSERT INTO ... (...) VALUES (...) ON DUPLICATE KEY UPDATE ...

It needs to get the corresponding pkey value when updated (it's a query that is updated when data piles up)

the problem occurs when the data is duplicated, (because of the unique key) the return value of conn_insert_id() is 0. (the problem doesn't occur when data is inserted)

the current solution I have is to retrieve pkey through a function that selects corresponding pkey when the return value is 0 for conn_insert_id(), but I want to know if it's possible to get pkey with out a separate select query?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.