Defines a new procedural language.
CREATE [PROCEDURAL] LANGUAGE <name>
CREATE [TRUSTED] [PROCEDURAL] LANGUAGE <name>
HANDLER <call_handler> [ INLINE <inline_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.
Note: Most procedural languages for Greenplum Database have been made into "extensions," and should therefore be installed with CREATE EXTENSION, not CREATE LANGUAGE
. Using CREATE LANGUAGE
directly should be restricted to extension installation scripts. If you have a "bare" language in your database, perhaps as a result of an upgrade, you can convert it to an extension using CREATE EXTENSION langname FROM unpackaged
.
Superusers can register a new language with a Greenplum database. A database owner can also register within that database any language listed in the pg_pltemplate
catalog in which the tmpldbacreate
field is true. The default configuration allows only trusted languages to be registered by database owners. The creator of a language becomes its owner and can later drop it, rename it, or assign ownership to a new user.
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. Therese procedural language packages are included in the standard Greenplum Database distribution: PL/pgSQL, PL/Perl, and PL/Python. Language handlers have also been added for PL/Java and PL/R, but those languages are 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 Broadcom Support Portal under the desired Greenplum release, 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
NoteFor more information about download prerequisites, troubleshooting, and instructions, see Download Broadcom products and software.
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.
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.
plpgsql
,
plperl
, and
plpythonu
. The languages
plpgsql
(PL/pgSQL) and
plpythonu
(PL/Python) are installed by default in Greenplum Database.
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.
inline_handler
function is not specified, the language does not support anonymous code blocks. The handler function must take one argument of type
internal
, which is the
DO command internal representation. The function typically return
void
. The return value of the handler is ignored.
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.
The PL/pgSQL language is already registered in all databases by default. The PL/Python language extension is installed but not registered.
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 is to use CREATE EXTENSION
instead of CREATE LANGUAGE
. For example:
CREATE EXTENSION plperl;
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.
ALTER LANGUAGE, CREATE EXTENSION, CREATE FUNCTION, DROP EXTENSION, DROP LANGUAGE, GRANT DO
Parent topic: SQL Command Reference