为什么行的第二次调用不会更改显示的日期?要更正每次需要重新创建连接时运行select now()?你知道吗
>>> import psycopg2
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2015, 9, 22, 19, 39, 9, 582080)
>>> sql ="""SELECT now();"""
>>> cursor.execute(sql)
>>> rows = cursor.fetchall()
>>> rows
[(datetime.datetime(2015, 9, 22, 19, 39, 31, 397308, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=180, name=None)),)]
>>> datetime.now()
datetime.datetime(2015, 9, 22, 19, 39, 58, 326446)
>>> cursor.execute(sql)
>>> rows = cursor.fetchall()
>>> rows
[(datetime.datetime(2015, 9, 22, 19, 39, 31, 397308, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=180, name=None)),)]
>>> sql ="""SELECT version();"""
>>> cursor.execute(sql)
>>> rows = cursor.fetchall()
>>> rows
[('PostgreSQL 9.1.13 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.7.2-5) 4.7.2, 64-bit',)]
离开@jornsharpe的评论,我打开了psycopg的文档。从他们的"Best Practices" FAQ:
因此,您的游标缓存数据,当您处理完该游标时,应该调用^{} 。据推测,这些游标是轻量级的,如果您的应用程序需要,重新创建其中的许多游标并不是一个坏主意。你知道吗
相关问题 更多 >
编程相关推荐