PL/pgSQL is a loadable,
, similar to the Oracle procedural language, PL/SQL. A
procedural language is a programming language used to specify a sequence of steps that are followed to produce an intended
You can use PL/pgSQL to group sequences of SQL and programmatic statements together within a database server, reducing
network and communications overhead incurred by client applications having to constantly request data from the database and
perform logic operations upon that data from a remote location.
You have access to all PostgreSQL data types, operators, and functions within PL/pgSQL code. The "SQL" in PL/pgSQL is
indicative of the fact that you are allowed to directly use the SQL language from within PL/pgSQL code. The use of SQL within
PL/pgSQL code can increase the power, flexibility, and performance of your programs. If multiple SQL statements are executed
from a PL/pgSQL code block, the statements are processed at one time, instead of the normal behavior of processing a single
statement at a time.
Another important aspect of using PL/pgSQL is its portability; its functions are compatible with all platforms that can
operate the PostgreSQL database system.
The following sections describe how to make PL/pgSQL available as a procedural language in your database.
Programming languages are made available to databases by being created as a database object. You will therefore need to
add the PL/pgSQL language to your database before you can use it (it is installed with PostgreSQL by default). The following
steps demonstrate how to add PL/pgSQL to an existing database.