Updating multiple columns in Sqlalchemy

Viewed 16425

I have an app that runs on flask and uses sqlalchemy to interact with the data base. I want to update the columns of a table with the user specified values. The query that I am using is

def update_table(value1, value2, value3):
     query = update(Table).where(Table.column1 == value1).values(Table.column2 = value2, Table.column3 = value3)

I am not sure if the way I am passing values is correct. Also the Table.column2/3 i=gives error saying Can't assign to function call . Where column2/3 are not functions, they're field names. So, how do I update multiple values and why is it giving error here?

PS: I referred the sqlalchemy doc

3 Answers

Using your previous structure:

def update_table(value1, value2, value3):
     query = update(Table).where(Table.column1 == value1).values( { Table.column2 : value2, Table.column3 : value3 } )
Related