A newer version of this documentation is available. Use the version menu above to view the most up-to-date release of the Greenplum 4.x documentation.
Defines a new procedural language.
CREATE [PROCEDURAL] LANGUAGE name CREATE [TRUSTED] [PROCEDURAL] LANGUAGE name HANDLER call_handler [VALIDATOR valfunction]
CREATE LANGUAGE registers a new procedural language with a Greenplum database. Subsequently, functions and trigger procedures can be defined in this new language. You must be a superuser to register a new language. The PL/pgSQL language is already registered in all databases by default.
CREATE LANGUAGE effectively associates the language name with a call handler that is responsible for executing functions written in that language. For a function written in a procedural language (a language other than C or SQL), the database server has no built-in knowledge about how to interpret the function's source code. 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, and so on or it could serve as a bridge between Greenplum Database 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 language packages included in the standard Greenplum Database distribution: PL/pgSQL, PL/Perl, PL/Python, and PL/Java. A language handler has also been added for PL/R, but the PL/R language package is not pre-installed with Greenplum Database. See the topic on Procedural Languages in the PostgreSQL documentation for more information on developing functions using these procedural languages.
The PL/Perl, PL/Java, and PL/R libraries require the correct versions of Perl, Java, and R to be installed, respectively.
On RHEL and SUSE platforms, download the appropriate extensions from Pivotal Network, then install the extensions using the Greenplum Package Manager (gppkg) utility to ensure that all dependencies are installed as well as the extensions. See the Greenplum Database Utility Guide for details about gppkg.
There are two forms of the CREATE LANGUAGE command. In the first form, the user specifies the name of the desired language and the Greenplum Database server uses the pg_pltemplate system catalog to determine the correct parameters. In the second form, the user specifies the language parameters as well as the language name. You can use the second form to create a language that is not defined in pg_pltemplate.
When the server finds an entry in the pg_pltemplate catalog for the given language name, it will use the catalog data even if the command includes language parameters. This behavior simplifies loading of old dump files, which are likely to contain out-of-date information about language support functions.
- Ignored if the server has an entry for the specified language name in pg_pltemplate. Specifies that the call handler for the language is safe and does not offer an unprivileged user any functionality to bypass access restrictions. If this key word is omitted when registering the language, only users with the superuser privilege can use this language to create new functions.
- This is a noise word.
- The name of the new procedural language. The language name is case insensitive. The name must be unique among the languages in the database. Built-in support is included for plpgsql, plperl, plpythonu, and plr. The languages plpgsql (PL/pgSQL) and plpythonu (PL/Python) are installed by default in Greenplum Database.
- HANDLER call_handler
- Ignored if the server has an entry for the specified language name in pg_pltemplate. 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 with version 1 call convention and registered with Greenplum Database as a function taking no arguments and returning the language_handler type, a placeholder type that is simply used to identify the function as a call handler.
- VALIDATOR valfunction
- Ignored if the server has an entry for the specified language name in pg_pltemplate. valfunction is the name of a previously registered function that will be called when a new function in the language is created, to validate the new function. If no validator function is specified, then a new function will not be checked when it is created. The validator function must take one argument of type oid, which will be the OID of the to-be-created function, and will typically return void.
- A validator function would typically inspect the function body for syntactical correctness, but it can also look at other properties of the function, for example if the language cannot handle certain argument types. To signal an error, the validator function should use the ereport() function. The return value of the function is ignored.
The PL/pgSQL and PL/Python language extensions are installed by default in Greenplum Database.
The system catalog pg_language records information about the currently installed languages.
To create functions in a procedural language, a user must have the USAGE privilege for the language. By default, USAGE is granted to PUBLIC (everyone) for trusted languages. This may be revoked if desired.
Procedural languages are local to individual databases. You create and drop languages for individual databases.
The call handler function and the validator function (if any) must already exist if the server does not have an entry for the language in pg_pltemplate. But when there is an entry, the functions need not already exist; they will be automatically defined if not present in the database.
Any shared library that implements a language must be located in the same LD_LIBRARY_PATH location on all segment hosts in your Greenplum Database array.
The preferred way of creating any of the standard procedural languages:
CREATE LANGUAGE plpgsql; CREATE LANGUAGE plr;
For a language not known in the pg_pltemplate catalog:
CREATE FUNCTION plsample_call_handler() RETURNS language_handler AS '$libdir/plsample' LANGUAGE C; CREATE LANGUAGE plsample HANDLER plsample_call_handler;
CREATE LANGUAGE is a Greenplum Database extension.