UPDATE table1 SET column1 = column2 WHERE column3 ='abc';
如何在sql alchemy ORM中执行上述查询
table1 = Table('table1', metadata,
Column("column1", SmallInteger(), nullable=False, autoincrement=False),
Column("column2", SmallInteger(), nullable=False, autoincrement=False),
Column("column3", String(length=255), nullable=False)
)
class Table1(object):
pass
mapper(Table1, table1)
答案 0 :(得分:1)
DBSession.query(table1).filter_by(column3 = 'abc').update({"column1":column2}, synchronize_session=False)
使用此
where ==== filter_by
table1 === class containing the table1 schema
update command with columns as key in query