In today’s article, we will explain what PostgreSQL Stored Procedure is and how to create it with the help of an example.
Stored Procedures provide ease of operation to run long queries in a single command.
Procedures are not used much in PostgreSQL. Functions are generally used instead of procedures. CALL command is used to run procedures.
In the language section of the procedure, it can be written in languages such as plpgsql, sql, c, plperl, and the rules observed in variable definition are also valid here.
Procedures are divided into two: parameterized and parameterless.
Parameterless sp: These are t-sql sentences that you run without writing anything next to the created sp.
Example:
1 2 3 4 5 6 |
create procedure parameterless() language plpgsql ace $$ begin raise notice 'This is a Parameterless Procedure '; end; $$ |
To run the procedure.
1 |
call parameterless(); |
Parameterized sp: These are plpgsql sentences that you run by typing a parameter next to the created sp.
Example:
1 2 3 4 5 6 |
create procedure with parameterized (d1 text,d2 text) language SQL ace $$ insert into veliler(adi, soyadi) values (d1,d2); $$; call parameterized ('Faruk ','ERDEM'); |