Passing variable to SQL statement when using psycopg2

Julia Jacobson julia.jacobson at arcor.de
Mon Aug 30 08:29:43 CEST 2010


Dear python users,

For passing a variable to a SQL query for psycopg2, I use:

  >>> my_var = xyz
  >>> print cur.mogrify("SELECT my_values FROM my_table WHERE my_column 
= %s",(my_var,))

This returns:

  >>> SELECT my_values FROM my_table WHERE my_column = E'xyz'

Where does the "E" in front of 'xyz' come from? It's probably the 
reason, why my query doesn't work.

Thanks in advance,
Julia



More information about the Python-list mailing list