How can I call cursor in python
CREATE OR REPLACE PROCEDURE WaterBillInMonth(
in p_Month INT,
INOUT refcur refcursor DEFAULT 'rs_resultone'::refcursor)
LANGUAGE 'plpgsql'
AS $BODY$
BEGIN
OPEN refcur for
SELECT u.username, w.prev_volume, w.cur_volume,
w.total_volume, w.price, w.total_volume_price, w.due_date, w.payment_date, w.created_at
FROM water_bills w JOIN users u ON w.user_id = u.id
WHERE p_Month = EXTRACT (MONTH FROM w.created_at);
END;
$BODY$;
-- call procedure
CALL WaterBillInMonth(4, 'rs_resultone');
FETCH ALL FROM rs_resultone;
I want to call cursor (query)
I want to call this from python to retrieve the results from the cursor.
stmt = text("CALL WaterBillInMonth(:p_month, 'rs_resultone')")
result = db.execute(stmt, {'p_month': p_month})
# bills = result.fetchall()
bills = result.fetchall()
print(bills)
# bills = db.execute(text("FETCH ALL FROM rs_resultone"))