Trying to run a postgresql procedure using python but not able to rectify the error..
def call_procedure_without_arguments():
try:
connection = create_connection()
if connection:
cursor = connection.cursor()
# Call the procedure without any input arguments
procname = "call proc_test"
cursor.callproc(procname)
results = cursor.fetchall()
print("Results:", results)
# Commit the changes (if any)
connection.commit()
# Close the cursor and connection
cursor.close()
connection.close()
print("Procedure executed successfully.")
else:
print("Connection failed. Unable to call the procedure.")
except Exception as e:
print("Error: Unable to call the procedure.", e)
if __name__ == "__main__":
call_procedure_without_arguments()
2
Answers
I am expecting that no arguments need to be passed. The documentation for this is different at different resources.
According to Geeks for Geeks
If does not work try adding parenthesis (), according to Postgresql Tutorial:
Contrary to the name
callproc
is not for procedures. It is for functions only:https://www.psycopg.org/docs/cursor.html#cursor.callproc
Therefore:
cur.execute('call proc_test')