问题
In the psycopg2 docs it references an sql property full of fun goodness for safely constructing SQL strings. Yet my install on python 3, which should be latest from PyPI, contains no such attribute:
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
So how can I safely construct SQL strings without it (I have zero interest in SQLAlchemy)? Or should I still have that and the fact that its missing is worrisome?
回答1:
It is new in Psycopg2 2.7. What is your version?
>>> psycopg2.__version__
'2.6.2 (dt dec pq3 ext lo64)'
http://initd.org/psycopg/docs/sql.html
来源:https://stackoverflow.com/questions/41883389/what-happened-to-psycopg2-sql