FAQ
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

Search Discussions

  • Chris Rebert at Aug 30, 2010 at 7:08 am

    On Sun, Aug 29, 2010 at 11:29 PM, Julia Jacobson wrote:
    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
  • Gregory Ewing at Aug 30, 2010 at 8:22 am

    Chris Rebert wrote:
    On Sun, Aug 29, 2010 at 11:29 PM, Julia Jacobson
    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
    Seems to be a postgres extension to the sql string literal syntax:

    http://issues.liferay.com/browse/LEP-3182

    --
    Greg

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 30, '10 at 6:29a
activeAug 30, '10 at 8:22a
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase