In PostgreSQL 11, procedures were introduced. The main difference between functions and procedures is transaction control. Functions are explicitly run in a transaction, while a procedure can control transactions. In procedures, you can explicitly COMMIT and ROLLBACK a transaction. Functions can be called within SQL code, but procedures are executed via CALL statements. Finally, functions should have a return data type; if the function does not return anything, the VOID pseudo data type can be used.
Procedures have great benefits. Let's suppose that we would like to index all foreign keys. In this case, using a function is not very practical, because the indexes are created when the function completely finishes the execution. So, if an exception occurs in the middle of the execution, then all of the work is lost. In a stored...