Escape Keys using psycopg2

Escape Keys using psycopg2

June 2, 2023

Found the information at https://www.psycopg.org/docs/usage.html#query-parameters.

Since % is used in both Python and in Postgres I need to use %% instead:

>>> cur.execute("SELECT (%s % 2) = 0 AS even", (10,))       # WRONG
>>> cur.execute("SELECT (%s %% 2) = 0 AS even", (10,))      # correct

or this:

f""" AND '{findings}' %%> ANY(STRING_TO_ARRAY(
      CONCAT("Finding1","Finding2","Finding3","Finding4","Finding5","Finding6")
      ,' '
      )
     )
"""

instead of this:

f""" AND '{findings}' %> ANY(STRING_TO_ARRAY(
      CONCAT("Finding1","Finding2","Finding3","Finding4","Finding5","Finding6")
      ,' '
      )
     )
"""