I'm using the similarity operator (%
) to query a pg_trgm index to perform a similarity search on my data and it happens to be that the %
is reserved by psycopg to do various things notably insert query parameters.
SELECT "s"."name", "s"."album", "s"."artist"
FROM "song" "s"
WHERE "s"."fts_col" % 'reflections'
ORDER BY similarity("s"."fts_col", %(p1)s) DESC, "s"."name", "s"."album", "s"."artist"
LIMIT 5
{'p1':'reflections'}
How can I escape the %
operator for psycopg not to error out on this kind of query?
Not using the operator is out of the question as Postgres will not use any index for the query otherwise, bringing up the execution time by a lot.