0

Are prepared statements written differently in psycopg3 than psycopg2?

I am upgrading from psycopg2 to 3 and in psycopg2 this works but doesnt work for psycopg3

Also the variables name and age will be populated with data

sql is a variable which is connected to the Database we use. So my problem is within the query itself and not the python syntax

def test(name, age=None, alive=False):


    sql.execute("""prepare test as UPDATE table AS x
                SET var = $1
                FROM table1 as y
                WHERE y.name = x.name and y.age = $2""")
   sql.execute("""execute test (%s, %s)""", (name, age))

This throws an error saying could not determine the datatype of parameter $1. Looking at the docs and github of psycopg, theres no info regarding this matter.

  • 1
    [psycopg3 prepared statements](https://www.psycopg.org/psycopg3/docs/advanced/prepare.html#prepared-statements): *Note however that Psycopg doesn’t use SQL statements such as PREPARE and EXECUTE, but protocol level commands such as the ones exposed by PQsendPrepare, PQsendQueryPrepared.*. Read the rest of the link for more information. – Adrian Klaver Jan 23 '23 at 17:41

0 Answers0