I have a function that returns a set of refcursors:
CREATE function func_name(func_date date) returns SETOF refcursor
language plpgsql
as
$$
DECLARE
ref1 refcursor := 'data_1';
ref2 refcursor := 'data_2';
BEGIN
OPEN ref1 FOR
SELECT * FROM users;
RETURN NEXT ref1;
OPEN ref2 FOR
SELECT * FROM roles;
RETURN NEXT ref2;
END;
$$;
I have the following code in Python which calls the function which returns a tuple of the refcursors. I need help as to how I can read these refcursors and add the data to a DataFrame
import psycopg2 as db
import datetime
# Connect to DB
conn = db.connect(host='abc', dbname='abc', user='a', password='abc',gssencmode="disable")
conn.set_session(autocommit=True)
func_date = datetime.date.today()
cur = conn.cursor()
cur.callproc('func_name', [func_date])
data = cur.fetchall()
for row in data:
a = row[0]
print(a)