CREATE LANGUAGE

Name

CREATE LANGUAGE  --  Defines a new language for functions

Synopsis

CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE langname
    HANDLER call_handler

Inputs

TRUSTED

TRUSTED specifies that the call handler for the language is safe; that is, it offers an unprivileged user no functionality to bypass access restrictions. If this keyword is omitted when registering the language, only users with the PostgreSQL superuser privilege can use this language to create new functions.

PROCEDURAL

Optional keyword that has no effect.

langname

The name of the new procedural language. The language name is case insensitive. A procedural language cannot override one of the built-in languages of PostgreSQL.

For backward compatibility, the name may be enclosed by single quotes.

call_handler

call_handler is the name of a previously registered function that will be called to execute the procedural language functions. The call handler for a procedural language must be written in a compiled language such as C and registered with PostgreSQL as a function taking no arguments and returning the opaque type (a placeholder for unspecified or undefined types). Refer to the Red Hat Database Programmer's Guide for details.

Outputs

CREATE

This message is returned if the language is successfully created.

ERROR: PL handler function funcname() does not exist

This error is returned if the function funcname() is not found.

Description

Using CREATE LANGUAGE, a PostgreSQL user can register a new language with PostgreSQL. Subsequently, functions and trigger procedures can be defined in this new language. The user must have the PostgreSQL superuser privilege to register a new language.

CREATE LANGUAGE effectively associates the language name with a call handler that is responsible for executing functions written in the language. Refer to the Red Hat Database Programmer's Guide for more information about language call handlers.

Note that procedural languages are local to individual databases. To make a language available in all databases by default, it should be installed into the template1 database before creating those databases.

Notes

This command normally should not be executed directly by users. For the procedural languages supplied in the PostgreSQL distribution, the createlang script should be used, which will also install the correct call handler. (createlang will call CREATE LANGUAGE internally.)

Use the CREATE FUNCTION command to create a new function.

Use DROP LANGUAGE or the droplang script to drop procedural languages.

The system catalog pg_language records information about the currently installed procedural languages.

The definition of a procedural language cannot be changed once it has been created.

        Table "pg_language"
   Attribute   |  Type   | Modifier
---------------+---------+----------
 lanname       | name    |
 lanispl       | boolean |
 lanpltrusted  | boolean |
 lanplcallfoid | oid     |
 lancompiler   | text    |

   lanname   | lanispl | lanpltrusted | lanplcallfoid | lancompiler
-------------+---------+--------------+---------------+-------------
 internal    | f       | f            |             0 | n/a
 C           | f       | f            |             0 | /bin/cc
 sql         | f       | f            |             0 | postgres

Usage

First, create a procedural language handler as described in the Red Hat Database Programmer's Guide. Next, use the following two commands executed in sequence to register the new procedural language and the associated call handler:
CREATE FUNCTION plsample_call_handler () RETURNS opaque
    AS '$libdir/plsample'
    LANGUAGE C;
CREATE LANGUAGE plsample
    HANDLER plsample_call_handler;

Compatibility

SQL92

There is no CREATE LANGUAGE statement in SQL92.