假设我的表只有两列:
我想选择step_id == 2
所在的行,并将start_date
(当前为空)更新为当前时间。目前,我正在做的是:
engine = create_engine('postgresql://postgres:postgres@localhost/quantdb')
metadata = MetaData(bind=engine)
step_instance = Table('step_instance', metadata, autoload=True)
s = step_instance.select().where(step_instance.c.step_id == 2)
res = engine.execute(s)
for row in res:
start_date_stmt = step_instance.update().where(step_instance.c.id == row.id).\
values(start_date=datetime.now(pytz.utc))
engine.execute(start_date_stmt)
这感觉很笨拙,有更好的方法吗?我在考虑在哪里可以直接修改row
中的字段,然后用这个修改后的row
来“更新”数据库。在
有可能吗?也很高兴听到其他更好的方法。在
是的,你可以。查找会话。我还没有测试下面的样本,但它给了你一个做什么的想法。在
相关问题 更多 >
编程相关推荐