cur.execute(
    """
    PREPARE prepared_select(text, int) AS
        SELECT * FROM test
        WHERE (name = $1 and rowid > $2) or name > $1
        ORDER BY name, rowid
        LIMIT 1
"""
    )
name = ''
rowid = 0
Python to Postgres interface with real prepared statements?