Closed Lawouach closed 2 years ago
Okay. See, sometimes opening an issue and your eyes open as well.
It was right there, the error was clear. I wasn't using the appropriate types for the arguments of the function. Here is what works:
from sqlalchemy import cast, literal_column
from sqlalchemy.dialects.postgresql import JSONB
s = select([func.jsonb_path_query(
cast(tt.c.col, JSONB),
literal_column("'$ ? (@.provider == $provider).services[*] ? (@.service == $svc).data ? (@.argument_name == $argname)'::jsonpath"),
cast({"provider": "A", "svc": "B", "argname": "C"}, JSONB)
)])
Note, that when you'll use SQLAlchemy 2, you'll probably prefer something like this:
from sqlalchemy import cast
from sqlalchemy.dialects.postgresql import JSONB, JSONPATH
s = select([func.jsonb_path_query(
cast(tt.c.col, JSONB),
cast("$ ? (@.provider == $provider).services[*] ? (@.service == $svc).data ? (@.argument_name == $argname)", JSONPATH),
cast({"provider": "A", "svc": "B", "argname": "C"}, JSONB)
)])
Does asyncpg supports the
jsonb_path_query
function? I get an error when trying to use it (whereas it works with psycopg2):Results in:
and
Is there something I'm missing to enable perhaps?