对表的评论未提交

时间:2019-03-11 14:57:56

标签: python postgresql sqlalchemy

在如下所示的表上执行注释时,似乎永远不会提交。

查看引擎日志记录,我看不到COMMIT执行。

# adding comment to table with creation date.
engine.execute("COMMENT ON TABLE can.src_add_lookup IS 'Table create date: {}';".format(datetime.utcnow()))
engine.execute("TRUNCATE TABLE can.src_add_lookup")

执行日志

INFO:sqlalchemy.engine.base.Engine:{}
INFO:sqlalchemy.engine.base.Engine:**COMMIT**
INFO:sqlalchemy.engine.base.Engine:CREATE UNIQUE INDEX idx_add_5b45adb005ee4da6b32ed0421df9314b ON can.src_add_lookup (id)
INFO:sqlalchemy.engine.base.Engine:{}
INFO:sqlalchemy.engine.base.Engine:**COMMIT**
INFO:sqlalchemy.engine.base.Engine:COMMENT ON TABLE can.src_add_lookup IS 'Table create date: 2019-03-11 14:37:49.843897';
INFO:sqlalchemy.engine.base.Engine:{}
INFO:sqlalchemy.engine.base.Engine:TRUNCATE TABLE can.src_add_lookup
INFO:sqlalchemy.engine.base.Engine:{}
INFO:sqlalchemy.engine.base.Engine:**COMMIT**

1 个答案:

答案 0 :(得分:0)

在查看IljaEverilä上的相关链接后,确定如下所示。

# adding comment to table with creation date.
comment = sqlalchemy.text("COMMENT ON TABLE {}.src_add_lookup IS 'Table create date: {}';".format(schema, datetime.utcnow())).execution_options(autocommit=True)
engine.execute(comment)