0

I need to get query results with multiple like filters, like this:

select *
from public.data 
where namep like '%YA%' and comm like '%comm' and state = %(region)s 
limit 10

But when I'm trying to execute this query with psycopg2 I'm getting the error:

'dict' object does not support indexing.

I found that this error occurs due to the first and second like statements with '%'. In my original query there several '%' symbols and like filter, so I can't change them.

I can't find any information,but is this possible to do some other filter for psycopg2?

eshirvana
  • 23,227
  • 3
  • 22
  • 38
FeoJun
  • 103
  • 1
  • 14
  • Does this answer your question? [How do I print a '%' sign using string formatting?](https://stackoverflow.com/questions/28343745/how-do-i-print-a-sign-using-string-formatting) – Maurice Meyer Mar 15 '21 at 13:38
  • 1
    ... you need to escape all 'static' occurrences of `%` by another `%`: `... where namep like '%%YA%%' ... ` – Maurice Meyer Mar 15 '21 at 13:39
  • @MauriceMeyer Thanks, your advice helped me, now it works – FeoJun Mar 15 '21 at 13:52

0 Answers0