How can I print postgres's stored procedure on python script?
Example of stored procedure in postgres is as below:
create or replace function checktime() returns void
language plpgsql
as $$
DECLARE timestart TIMESTAMP;
FOR id from rt LOOP
SELECT timeofday() into timestart;
RAISE NOTICE 'Time now : %', timestart;
END LOOP;
END;
$$
;
From python, my script is:
import psycopg2
conn = psycopg2.connect(host="", database="",
user="", password="")
print("Database Connected")
cur = conn.cursor()
rowcount = cur.rowcount
cur.callproc('rt_visits_function_gz')
# how can i display the raise notice in here?
I would like for each loop the result is displayed when i run python.
Thank you
Try using 'notices'
print(conn.notices)
http://initd.org/psycopg/docs/connection.html?highlight=notice#connection.notices
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With