you are at >> pgSQL >>introduction
PL/pgSQL
PL/pgSQL is loadable procedural language, which allows :- creating trigger procedures and functions
- extend SQL with control structures similar to a procedure language
To install the PL / PgSQL language to the database, you can use the CREATE LANGUAGE in psql to load and use the shared library or a script assistant from a user called postgres.
createlang plpgsql database_name
This is the language of block-structural, similar to Pascal or C,
with declarations of variables and groups of blocks. Each block has an optional
label and may have some variables and declarations. Instructions are placed between
keywords BEGIN and END.
[< < label > >]
declare declarations
begin
instructions
end ;
Commands of PL/pgSQL language aren't case sensitive.
Functions in PL / PgSQL can not have arguments or they may have several.
Type of parameters is given in parenthesis after the function name. You can
use built-in types of PostgreSQL such as float8 and int4. In body of the function
you can use given parameters in such form : $1, $2 etc. in order of their definition.
There is possibility of giving names for parameters using ALIAS declaration.
All procedures which are kept in database must return result. Type of returned result
is specyfing in RETURNS clause in funcion definition.
[ wróć na górę strony ]