I'm trying to use the json #>> text[] → text operator on my Postgres database through peewee, as documented through https://www.postgresql.org/docs/current/functions-json.html. For example, running the query select * from table where UPPER(data #>> '{a}') = UPPER('search_string')
I seem to be having some trouble however getting this to work. I have tried using the raw where = SQL("UPPER(%s #>> '{a}') = UPPER(%s)", MyTable.data, search_string)). Though am running into a number of errors here (SQL can only take one format parameter it seems. I've tried weird work-arounds but it also doesn't seem to be happy parsing '{a}'). I've also tried writing it as a peewee Expression, though can't seem to get the desired output either. Writing the code below seems to try to cast '{a}' to json first in the finalized Postgres query, which results in an error.
def text_equals(lhs, rhs):
return Expression(lhs, '#>>', rhs)
text_equals(MyTable.data, '{a}')
Any advice would be greatly appreciated!!!