psycopg2 for insertion of binary data to PostgreSQL database

Peter Otten __peter__ at web.de
Mon Aug 23 04:13:36 EDT 2010


Julia Jacobson wrote:

> How can I assign the result of a SQL query to a variable?
> The following code snippet doesn't work:
> query_result=cur.execute("SELECT column_name FROM table_name WHERE
> my_variable = 'my_value'",)

To retrieve an image from a table "images" by its name you could do 
(untested):

name = "image001.jpg"
row = cur.execute("select image from images where name = %s", 
(name,)).fetchone()
if row is None:
    raise ValueError("no image %r found" % name)
image = row[0]




More information about the Python-list mailing list