Call Postgres SQL stored procedure From Django
c = connection.cursor()
try:
c.execute("BEGIN")
c.callproc("fn_save_message3", (Message_Subject, Message_Content, Message_Type, Message_Category, Created_By, Updated_By))
results = c.fetchall()
c.execute("COMMIT")
finally:
c.close()
print results
You forgot the closing parens and were trying to call the functions on cursor
instead of c
and also had an issue with indentation. You should also use the callproc()
function as documented here.
As catavaran said, you should read the documentation on executing custom SQL and use placeholders. Also, in Django 1.6+, the transactions are commited automatically so there is no need for c.execute("COMMIT")