我正在尝试SET
从 sqlalchemy 执行语句。
>>> from sqlalchemy import create_engine
>>> c = create_engine('postgres://myuser@myremoteserver/mydb?keepalives_idle=4&keepalives_interval=1&keepalives_count=5')
>>> c.execute('SET statement_timeout=1000')
<sqlalchemy.engine.base.ResultProxy object at 0xb7b250>
它将返回ResultProxy
对象。statement_timeout
但未设置值。
>>> c.execute('SHOW statement_timeout').scalar()
'0'
如果我会尝试ResultProxy.scalar
,那么它会给出错误。
>>> c.execute('SET statement_timeout=1000').scalar()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1676, in scalar
self.connection._handle_dbapi_exception(e, None, None, self.cursor, self.context)
File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 923, in _handle_dbapi_exception
self.invalidate(e)
File "/usr/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 633, in invalidate
raise exc.InvalidRequestError("This Connection is closed")
sqlalchemy.exc.InvalidRequestError: This Connection is closed
如何设置这个变量的值?