1 回答
TA贡献1805条经验 获得超10个赞
从表中查找实际列并将其解包为以下参数CONCAT():
key_cols = [self.tbl.c[name.strip()] for name in key_col_names.split(",")]
stmt = self.tbl.update().where(self.tbl.c.master_key==None).\
values({'master_key': func.MD5(func.concat(*key_cols))})
qry_engine.execute(statement=stmt)
如果有问题的列具有字符串类型,+请在 Python 中使用运算符来生成连接表达式:
key_cols = [self.tbl.c[name.strip()] for name in key_col_names.split(",")]
# This is a bit of a hack and effectively the same as using reduce and operator.add.
# Another option would be to use a good old for-loop to reduce.
key_col_cat = sum(key_cols)
stmt = self.tbl.update().where(self.tbl.c.master_key==None).\
values({'master_key': func.MD5(key_col_cat)})
qry_engine.execute(statement=stmt)
添加回答
举报