Stored Procedures
About
Stored procedures do not return values with RETURN, so the use of RETURN is only to immediatly stop the procedure. (check Stored Procedures)
Unlike Functions, stored procedures support transactions.
Creating
The syntax is very similar to Functions.
CREATE OR REPLACE PROCEDURE procedure_name(p1 type, ...) AS
$$
DECLARE
-- variables..
BEGIN
-- statements..
END;
$$ LANGUAGE plpgsqlWith transactions
To make a procedure use a transaction, just add COMMIT at the of the block.
Calling
You can't call procedures within SELECT like you could in functions.
Deleting
Since procedures can be overloaded, Postgres need to know which procedure you want to remove by checking the argument_list.
Usage
Returning a value
You can use INOUT parameter mode to "return" a value.
At the end of the procedure the value in this parameter will be returned.
Last updated