How do I use parameterized queries with LIKE?

From: "W(dot) Matthew Wilson" <matt(at)tplus1(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: How do I use parameterized queries with LIKE?
Date: 2012-05-28 22:00:03
Message-ID: CAGHfCUCgkAgbQvyc4EH8-T=goVBjjM0Q=O9Vsjoc6M+Cy8BARg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

This works just fine:

cursor.execute("""select email_address from customer where
email_address like '%matt%'""")

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?

Thanks for the help.

Matt

--
W. Matthew Wilson
matt(at)tplus1(dot)com
http://tplus1.com

Responses

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2012-05-28 22:13:27 Re: How do I use parameterized queries with LIKE?
Previous Message Andy Casey 2012-05-21 08:49:44 Re: Using a psycopg2 converter to retrieve bytea data from PostgreSQL