On Mon, May 28, 2012 at 11:00 PM, W. Matthew Wilson <matt@tplus1.com> wrote:
> But when I move the "matt" part out and use a %s symbol instead, I get
> this error:
>
> ValueError: unsupported format character ''' (0x27) at index 73
>
> What is the right solution here?
If you have parameters in the query, % is used as placeholder prefix.
You must use %% to include a literal % in the query:
In [14]: cur.execute("""select email_address from customer where
email_address like '%%' || %s || '%%'""", ('matt',))
or you can add the % to the value instead of the query:
In [17]: cur.execute("""select email_address from customer where
email_address like %s""", ('%matt%',))
Hope this helps,
-- Daniele