

Chapter 36. Procedural Languages

PostgreSQL allows users to add new programming languages to be available for writing functions and procedures. These are called procedural languages (PL). In the case of a function or trigger procedure 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 special C language function compiled into a shared object and loaded on demand.

Writing a handler for a new procedural language is described in Chapter 47. Several procedural languages are available in the standard PostgreSQL distribution, which can serve as examples.

36.1. Installing Procedural Languages



createlang plpgsql template1


Manual Procedural Language Installation

A procedural language is installed in a database in three steps, which must be carried out by a database superuser. The createlang program automates step 2 and step 3.


  2. The handler must be declared with the command

    CREATE FUNCTION handler_function_name()
        RETURNS language_handler
        AS 'path-to-shared-object'
        LANGUAGE C;


  3. The PL must be declared with the command

        HANDLER handler_function_name;


Example 36-1 shows how the manual installation procedure would work with the language PL/pgSQL.

Example 36-1. Manual Installation of PL/pgSQL


CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler AS
    '$libdir/plpgsql' LANGUAGE C;

The command

    HANDLER plpgsql_call_handler;



Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group