Passing a record to postgres procedure from psycopg2

Viewed 134

I have written a postgres procedure which takes a record as an input

CREATE OR REPLACE PROCEDURE public.foo(
    file_record record)
LANGUAGE 'plpgsql'
AS $$
DECLARE
    ...;
BEGIN
    ...;
END;
$$

In python I am then using a cursor to make a query which reads a record from another table and I would like to pass this record to the public.foo procedure.

How can I accomplish this?

My current approach was this:

rdCur = conn.cursor(cursor_factory=extras.RealDictCursor)
rdCur.execute(<some sql query>)

rdCur2 = conn.cursor(cursor_factory=extras.RealDictCursor)
sql_query2 = 'CALL public.foo(%s);

for record in rdCur:
    rdCur2.execute(sql_query2, record)

but unfortunately this does not work. I also tried extras.execute_values but that didn't help either.

0 Answers
Related