In an existing PostgreSQL table, I would like to UPDATE
several existing columns with values from a dictionary lookup (see dict below). Somewhat like described in this nice blog post. However, I can't figure out how to do that with a Python dictionary. Here comes the terrible pseudo-code:
d = {10:'chair', 11:'table', 12:'lamp',
20:'english ivy', 21:'peace lily', 22:'spider plant'}
curs.execute("""
UPDATE my_table t
SET furniture = %(t.furniture)s,
SET plant = %(t.plant)s""",
d)
The original table would look somewhat like this:
gid | furniture | plant
-----------------------
0 | 10 | 21
1 | 11 | 20
...
After the operation it should look like this:
gid | furniture | plant
-----------------------------
0 | chair | peace lily
1 | table | english ivy
...
Is this possible or will I have to loop through the table?