UPDATE SET values from list

Viewed 13848

I have a problem updating a table with new values from a list.

My data looks like this:

id  value_1  value_2

1   11       21

2   32       41

3   43       84

... 

I already wrote the column id and value_1 with an INSERT command in the table. At that step, I cannot write the value_2 column as I still need to calculate it, so I want to update the table later with an array of values of the value_2 column.

I would like to have a code something like this:

UPDATE table_name SET value_2 = (21,41,84) WHERE id IN (1,2,3)

Unfortunately, it's not possible like this to SET value_2 from a list, it works only with single values.

I got a workaround with writing a for loop over the whole UPDATE query, but this was too slow for my program. Anyone has a suggestion how I could get this working?

The whole query is performed with Python.

2 Answers
Related