使用psycopg准备的语句 [英] prepared statements using psycopg
问题描述
我是python的初学者。我们使用此代码执行SQL命令。
I'm a beginner at python. We use this code to execute SQL commands.
cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (100, "abcdef"))
我想知道这是准备好的语句还是
I wonder is this prepared statement or just a client side quoting?
推荐答案
不,至少不是psycopg2。文档中的准备是指准备交易,与准备好的陈述完全不同。
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
请请参阅:有关psycopg的博客条目。
更多信息:
http://www.postgresql.org/docs/9.2/static/sql-prepare.html
http://www.postgresql.org/docs/current/static/sql-prepare-transaction.html
这篇关于使用psycopg准备的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!