Defines a new procedural language.
CREATE [ OR REPLACE ] [ PROCEDURAL ] LANGUAGE <name>
CREATE [ OR REPLACE ] [ 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 procedures can be defined in this new language.
NoteProcedural languages for Greenplum Database have been made into "extensions," and should therefore be installed with CREATE EXTENSION, not
CREATE LANGUAGE
. UsingCREATE 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 usingCREATE EXTENSION <langname> FROM unpackaged
.
CREATE LANGUAGE
effectively associates the language name with handler function(s) that are responsible for executing functions written in the language.
There are two forms of the CREATE LANGUAGE
command. In the first form, the user supplies just the name of the desired language, and the Greenplum Database server consults the pg_pltemplate
system catalog to determine the correct parameters. In the second form, the user supplies the language parameters along with the language name. The second form can be used to create a language that is not defined in pg_pltemplate
, but this approach is considered obsolete.
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.
Ordinarily, the user must have the Greenplum Database superuser privilege to register a new language. However, the owner of a database can register a new language within that database if the language is listed in the pg_pltemplate
catalog and is marked as allowed to be created by database owners (tmpldbacreate
is true
). The default is that trusted languages can be created by database owners, but this can be adjusted by superusers by modifying the contents of pg_pltemplate
. The creator of a language becomes its owner and can later drop it, rename it, or assign it to a new owner.
CREATE OR REPLACE LANGUAGE
will either create a new language, or replace an existing definition. If the language already exists, its parameters are updated according to the values specified or taken from pg_pltemplate
, but the language's ownership and permissions settings do not change, and any existing functions written in the language are assumed to still be valid. In addition to the normal privilege requirements for creating a language, the user must be superuser or owner of the existing language. The REPLACE
case is mainly meant to be used to ensure that the language exists. If the language has a pg_pltemplate
entry then REPLACE
will not actually change anything about an existing definition, except in the unusual case where the pg_pltemplate
entry has been modified since the language was created.
TRUSTED
specifies that the language does not grant access to data that the user would not otherwise have. If this key word is omitted when registering the language, only users with the Greenplum Database superuser privilege can use this language to create new functions.
language_handler
type, a placeholder type that is simply used to identify the function as a call handler.
internal
, which is the
DO command internal representation. The function typically returns
void
. The return value of the handler is ignored.
oid
, which will be the OID of the to-be-created function, and will typically return
void
.
ereport()
function. The return value of the function is ignored.
NoteThe
TRUSTED
option and the support function name(s) are ignored if the server has an entry for the specified language name inpg_pltemplate
.
Use DROP LANGUAGE to drop procedural languages.
The system catalog pg_language records information about the currently installed languages. Also, the psql command \dL
lists the 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. However, a language can be installed into the template1
database, which will cause it to be available automatically in all subsequently-created databases.
The call handler function, the inline handler function (if any), 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. (This might result in CREATE LANGUAGE
failing, if the shared library that implements the language is not available in the installation.)
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, a sequence such as this is needed:
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 LANGUAGE, GRANT, DO
Parent topic: SQL Commands