| От | Adrian Klaver |
|---|---|
| Тема | Re: How do I use parameterized queries with LIKE? |
| Дата | |
| Msg-id | 4FC3F887.7010205@gmail.com обсуждение исходный текст |
| Ответ на | How do I use parameterized queries with LIKE? ("W. Matthew Wilson" <matt@tplus1.com>) |
| Список | psycopg |
On 05/28/2012 03:00 PM, W. Matthew Wilson wrote:
> 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?
http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries
So you need something like:
cursor.execute("""select email_address from customer where
email_address like %s""", ("matt",))
Note in particular the ("matt",). The parameters in this form need to be passed
as a tuple.
>
> Thanks for the help.
>
> Matt
>
--
Adrian Klaver
adrian.klaver@gmail.com
В списке psycopg по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера