简体   繁体   中英

How can I check if a certain column (using WHERE) exists in MySQL using Python's mysql-connector?

So I'd create multiple columns with ids that are not in order and I'd want to check if one of the ids is already in use, for example before doing UPDATE.. SET.. WHERE id = 123;I'd like to be able to check if the column with id=123 already exists or if I'd have to create a new one. I'm using mysql-connector with python 3.8 for this.

You are probably looking for the INSERT... ON DUPLICATE KEY UPDATE statement. Regardless of the programming language or the mysql connector, INSERT... ON DUPLICATE KEY UPDATE query will try to insert the provided data and if the data exists (based on unique indexes) will update them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM