Defines a new procedural language.



       HANDLER <call_handler> [VALIDATOR <valfunction>]


CREATE LANGUAGE registers a new procedural language with a HAWQ database. Subsequently, functions can be defined in this new language. You must be a superuser to register a new language.

When you register a new procedural language, you effectively associate 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 HAWQ 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 two forms of the CREATE LANGUAGE command. In the first form, the user specifies the name of the desired language and the HAWQ 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.

Indicates that this is a procedural language.

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, plpython, plpythonu, and plr. plpgsql is installed by default in HAWQ.

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 HAWQ 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 procedural language packages included in the standard HAWQ distribution are:

  • PL/pgSQL - registered in all databases by default
  • PL/Perl
  • PL/Python
  • PL/Java

HAWQ supports a language handler for PL/R, but the PL/R language package is not pre-installed with HAWQ.

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. 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 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 HAWQ array.


The preferred way of creating any of the standard procedural languages in a database:


For a language not known in the pg_pltemplate catalog:

CREATE FUNCTION plsample_call_handler() RETURNS 
    AS '$libdir/plsample'
    HANDLER plsample_call_handler;


CREATE LANGUAGE is a HAWQ extension.

See Also