postgresql 使用 psycopg 准备好的语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9866350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
prepared statements using psycopg
提问by Majid Azimi
I'm a beginner at python. We use this code to execute SQL commands.
我是python的初学者。我们使用此代码来执行 SQL 命令。
cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (100, "abcdef"))
I wonder is this prepared statement or just a client side quoting?
我想知道这是准备好的声明还是只是客户端引用?
回答by Brian
No, it does not, not for psycopg2 at least. The "Prepare" in the docs refers to a "PREPARE TRANSACTION" which is entirely different than a prepared statement.
不,它不会,至少对于 psycopg2 不会。文档中的“准备”指的是“准备交易”,它与准备好的语句完全不同。
You can emulate a prepared statement, by overriding the methods or executing extra statements, however. See: An example of psycopg2 cursor supporting prepared statements
但是,您可以通过覆盖方法或执行额外的语句来模拟准备好的语句。请参阅:支持准备语句的 psycopg2 游标示例
Please see: relevant blog entry for psycopg.
More information:
更多信息:
http://www.postgresql.org/docs/9.2/static/sql-prepare.html
http://www.postgresql.org/docs/current/static/sql-prepare-transaction.html
http://www.postgresql.org/docs/9.2/static/sql-prepare.html
http://www.postgresql.org/docs/current/static/sql-prepare-transaction.html