0

I can't use executemany function at all from pymysql, I'm using this reduced example:

cursor = self.connection.cursor()
sql_query = f"UPDATE lançamento SET {column_name} = %s WHERE STR_TO_DATE(Data, '%d/%m/%Y') > %s AND Caixa = %s;"
cursor.executemany(sql_query, [(str(value), str(current_date), self.back_end_insert_caixa_name) for value in values])

all values are as str, but I get the exception:

%d format: a real number is required, not str

the type of column_name in my sql database is float but when I try change %s to %f and str(value) to float(value) I get this exception:


a real number is required not str

How do I solve this?

  • This is not a hard bug. To use a literal % sign, you need to double it. `STR_TO_DATE(Data, '%%d/%%m/%%Y')`. – Tim Roberts Jun 12 '23 at 17:33
  • However, since `current_date` and `self.back_end_insert_caixa_name` do not change, this is going to update the SAME record over and over and over. Only the last value will survive. This can't be what you really intended. – Tim Roberts Jun 12 '23 at 17:36
  • in SQL you don't care about the type, alwways use `%s` and `[(value, current_date, self.back_end_insert_caixa_name) for value in values]` the SQL lib will handle everyting for you – azro Jun 12 '23 at 17:37
  • so was the problem about using f string? – DAVI AMÉRICO Jun 12 '23 at 17:40
  • worked fine thanks – DAVI AMÉRICO Jun 12 '23 at 20:38

0 Answers0