|
|
| · · · · · · · | |
pgAdmin 1.4 online documentationChapter 35. Procedural LanguagesTable of Contents PostgreSQL allows user-defined functions to be written in other languages besides SQL and C. These other languages are generically called procedural languages (PLs). For a function written in a procedural language, the database server has no built-in knowledge about how to interpret the function's source text. Instead, the task is passed to a special handler that knows the details of the language. The handler could either do all the work of parsing, syntax analysis, execution, etc. itself, or it could serve as “glue” between PostgreSQL and an existing implementation of a programming language. The handler itself is a C language function compiled into a shared object and loaded on demand, just like any other C function. There are currently four procedural languages available in the standard PostgreSQL distribution: PL/pgSQL (Chapter 36, PL/pgSQL - SQL Procedural Language), PL/Tcl (Chapter 37, PL/Tcl - Tcl Procedural Language), PL/Perl (Chapter 38, PL/Perl - Perl Procedural Language), and PL/Python (Chapter 39, PL/Python - Python Procedural Language). Other languages can be defined by users. The basics of developing a new procedural language are covered in Chapter 46, Writing A Procedural Language Handler. There are additional procedural languages available that are not included in the core distribution. Appendix H, External Projects has information about finding them. 35.1. Installing Procedural Languages A procedural language must be “installed” into each
database where it is to be used. But procedural languages installed in
the database For the languages supplied with the standard distribution, it is
only necessary to execute createlang plpgsql template1
The manual procedure described below is only recommended for
installing custom languages that Manual Procedural Language Installation A procedural language is installed in a database in four steps,
which must be carried out by a database superuser. (For languages
known to
Example 35.1, “Manual Installation of PL/pgSQL” shows how the manual installation procedure would work with the language PL/pgSQL. Example 35.1. Manual Installation of PL/pgSQL The following command tells the database server where to find the shared object for the PL/pgSQL language's call handler function. CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler AS
'$libdir/plpgsql' LANGUAGE C;
PL/pgSQL has a validator function, so we declare that too: CREATE FUNCTION plpgsql_validator(oid) RETURNS void AS
'$libdir/plpgsql' LANGUAGE C;
The command CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql
HANDLER plpgsql_call_handler
VALIDATOR plpgsql_validator;
then defines that the previously declared functions
should be invoked for functions and trigger procedures where the
language attribute is In a default PostgreSQL installation, the handler for the PL/pgSQL language is built and installed into the “library” directory. If Tcl support is configured in, the handlers for PL/Tcl and PL/TclU are also built and installed in the same location. Likewise, the PL/Perl and PL/PerlU handlers are built and installed if Perl support is configured, and the PL/PythonU handler is installed if Python support is configured. |