在psycopg2文档中,它引用了一个充满乐趣的sql属性,以安全地构造strings。然而,我在python 3上的安装(应该是来自PyPI的最新版本)不包含这样的属性:
from psycopg2 import sql
# ImportError: cannot import name 'sql'
import psycopg2
print(dir(psycopg2)) # no mention of sql, although dir is not complete
# in the REPL
help(psycopg2) # no mention of the sql submodule that I saw那么,如果没有它,我如何安全地构造SQL字符串(我对SQLAlchemy没有兴趣)?或者我还应该拥有它,而它的缺失是令人担忧的呢?
发布于 2017-01-26 21:43:35
它在Psycopg2 2.7中是新的。你的版本是什么?
>>> psycopg2.__version__
'2.6.2 (dt dec pq3 ext lo64)'http://initd.org/psycopg/docs/sql.html
https://stackoverflow.com/questions/41883389
复制相似问题