Passing variable to SQL statement when using psycopg2

J

Julia Jacobson

Dear python users,

For passing a variable to a SQL query for psycopg2, I use:
= %s",(my_var,))

This returns:

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
 
C

Chris Rebert

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.

Quite doubtful, considering the example in the psycopg2 docs also has the E:
http://initd.org/psycopg/docs/cursor.html#cursor.mogrify

Cheers,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top