logo       

Re: query: msg#00074

python.db.psycopg.devel

Subject: Re: query

Timothy Smith wrote:
> i'm migrating from pypgsql to psycopg, and psycopg has an issue with
> this query string.
>
> curpg.execute("""SELECT till_name,till_float
> FROM till_config
> JOIN transactions
> USING (id)
> WHERE for_venue = %s""",(Venue))

Are you sure this is the code you're actually running? I suspect you've
really got:

curpg.execute("""SELECT till_name,till_float
FROM till_config
JOIN transactions
USING (id)
WHERE for_venue = %s""" % (Venue))

^^^
Note the use of the Python string formatting operation rather than
passing the tuple (more on that in a below) to psycopg.

Also "(Venue)" does not create a tuple but "(Venue,)" does. Without the
extra "," the parentheses only affect the precedence which has no affect
here anyway.

Anyway, make sure you're using the following and I suspect you'll be ok:

curpg.execute("""SELECT till_name,till_float
FROM till_config
JOIN transactions
USING (id)
WHERE for_venue = %s""", (Venue,))

Cheers, Matt


>
> the error is as follows
>
> psycopg.ProgrammingError: ERROR: syntax error at or near "Cow" at
> character 102
>
> SELECT till_name,till_float
> FROM till_config
> JOIN transactions
> USING (id)
> WHERE for_venue = Mad Cow
>
> now i understand why it's erroring on that sql, but why isn't psycopg
> quoting it for me?
>
> _______________________________________________
> Psycopg mailing list
> Psycopg-IAPFreCvJWPBWskQ1e/+sw@xxxxxxxxxxxxxxxx
> http://lists.initd.org/mailman/listinfo/psycopg

--
__
/ \__ Matt Goodall, Pollenation Internet Ltd
\__/ \ w: http://www.pollenation.net
__/ \__/ e: matt-OIHT2ptovUgKF18QYN8mfw@xxxxxxxxxxxxxxxx
/ \__/ \ t: +44 (0)113 2252500
\__/ \__/
/ \ Any views expressed are my own and do not necessarily
\__/ reflect the views of my employer.


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise