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()
cursor.callproc()should just be the procedure name, it shouldn't havecallbefore it. Soprocname = 'proc_test'callproc()can't be used with procedures only functions. See my answer for doc reference.