Do you guys know how to UPDATE a database from a python list without using cur.executemany? Using cur.executemany I have problems in API calls or something. What is another way to solve this below? Thank you!
import psycopg2
conn = psycopg2.connect(DATABASE_URL) # Postgres
cur = conn.cursor()
list_account = [('Bob', 55), ('John', 10)]
cmd_type = ("""
UPDATE db.table
SET name = %s
WHERE age = %s""")
cur = conn.cursor()
cur.executemany(cmd_type, list_people)
I know below is crazy ugly, but I did that.
for i in range(len(list_account)):
cmd_type = ("""
UPDATE db.table
SET name = '{}'
WHERE age = '{}'""".format(list_account[i][0], list_account[i][1]))
cur = conn.cursor()
cur.execute(cmd_type)
conn.commit()