I want to fill NULL values of a column in table by iterating key and value of the dictionary.
My table is like below
| item_name | item_value |
|---|---|
| A | NULL |
| B | NULL |
| C | NULL |
| D | NULL |
and my dictionary is like below
dict = {'A': '%', 'B': 'COUNT', 'C': 'COUN', 'D': 'PSI'}
What I'm trying now is
value = (value, key)
for key, value in dict.items():
cursor.execute("INSERT INTO table(item_value) values(%s) where item_name =(%s)", value)
conn.commit()
cursor.close()
the output I want is
| item_name | item_value |
|---|---|
| A | % |
| B | COUNT |
| C | COUN |
| D | PSI |
Would this code accomplish what I want to do?