0

I need to insert a record from python into mysql, at the same time, if the birthday is equal to '9999-11-11', like below picture, enter image description here

then the birthday needs to be updated with the new birthday. The code is as below:

INSERT IGNORE INTO client
            (full_name, first_name, last_name, birthday, diagnose)
            VALUES (%s, %s, %s, %s,%s) 
            ON DUPLICATE KEY UPDATE
            birthday = IF(birthday='9999-11-11', %s, birthday); 

The problem is: with birthday = IF(birthday='9999-11-11', %s, birthday) how can I refer to the %s is new birthday?
Thanks in advance.

3
  • Can you provide more details on the insert logic? I'm assuming that you have a bunch of data on your python code, then for each entry you need to update on the mysql following your rule. I'm confused because you mentioned python lists on the question title, but your code does not have any Sep 16, 2020 at 14:46
  • Thank you. You are right. There is no list, just a bunch of data.
    – Annie
    Sep 16, 2020 at 15:01
  • I think I might have found the solution like below:"""INSERT IGNORE INTO client (full_name, first_name, last_name, birthday, diagnose) VALUES (%s, %s, %s, %s,%s) ON DUPLICATE KEY UPDATE birthday = IF(birthday='9999-11-11', %s, birthday); """,(full_name, first_name, last_name, birthday, diagnose,birthday)
    – Annie
    Sep 16, 2020 at 15:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.