Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

psycopg by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group