Stack Exchange
WHERE IN psycopg2 clause not formatting
I have been having trouble using WHERE $VARIABLE IN clauses in psycopg2:
from app.commons.database import conn

from psycopg2 import sql
from psycopg2.extras import DictCursor

query = '''
    SELECT
        *
    FROM
        {}.{}
    WHERE
        {} in %s
    '''.format(
        sql.Identifier('information_schema'),
        sql.Identifier('tables'),
        sql.Identifier('table_schema')
    )

data = (
    'information_schema',
    'pg_catalog'
)

with conn.cursor(cursor_factory=DictCursor) as cursor:
    cursor.execute(query, data)
    print(cursor.fetchall())

raises

TypeError: not all arguments converted during string formatting

I've read the seemingly hundreds of posts on this same topic, and the overwhelming answer has been: "you need to use tuples when submitting data as the second argument to cursor.execute". I've been doing that and still can't seem to determine where the gap is.

Check out the psycopg2 documentation on Lists adaptation
You are getting that error because psycopg2 is trying to substitute the two parameters, but you only gave it one parameter.  Try changing to this:
from app.commons.database import conn

from psycopg2 import sql
from psycopg2.extras import DictCursor

query = '''
    SELECT
        *
    FROM
        {}.{}
    WHERE
        {} =ANY(%s)
    '''.format(
        sql.Identifier('information_schema'),
        sql.Identifier('tables'),
        sql.Identifier('table_schema')
    )

data = [
    'information_schema',
    'pg_catalog'
] # A list now, instead of a tuple

with conn.cursor(cursor_factory=DictCursor) as cursor:
    cursor.execute(query, (data, )) # A tuple, containing your list
    print(cursor.fetchall())

