Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prepared statements using psycopg

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?

like image 446
Majid Azimi Avatar asked Mar 26 '12 03:03

Majid Azimi


1 Answers

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.

You can emulate a prepared statement, by overriding the methods or executing extra statements, however. See: An example of psycopg2 cursor supporting prepared statements

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

like image 185
Brian Avatar answered Sep 30 '22 14:09

Brian