2 40.1. Installing Procedural Languages #
4 A procedural language must be “installed” into each database where it
5 is to be used. But procedural languages installed in the database
6 template1 are automatically available in all subsequently created
7 databases, since their entries in template1 will be copied by CREATE
8 DATABASE. So the database administrator can decide which languages are
9 available in which databases and can make some languages available by
12 For the languages supplied with the standard distribution, it is only
13 necessary to execute CREATE EXTENSION language_name to install the
14 language into the current database. The manual procedure described
15 below is only recommended for installing languages that have not been
16 packaged as extensions.
18 Manual Procedural Language Installation
20 A procedural language is installed in a database in five steps, which
21 must be carried out by a database superuser. In most cases the required
22 SQL commands should be packaged as the installation script of an
23 “extension”, so that CREATE EXTENSION can be used to execute them.
24 1. The shared object for the language handler must be compiled and
25 installed into an appropriate library directory. This works in the
26 same way as building and installing modules with regular
27 user-defined C functions does; see Section 36.10.5. Often, the
28 language handler will depend on an external library that provides
29 the actual programming language engine; if so, that must be
31 2. The handler must be declared with the command
32 CREATE FUNCTION handler_function_name()
33 RETURNS language_handler
34 AS 'path-to-shared-object'
37 The special return type of language_handler tells the database
38 system that this function does not return one of the defined SQL
39 data types and is not directly usable in SQL statements.
40 3. Optionally, the language handler can provide an “inline” handler
41 function that executes anonymous code blocks (DO commands) written
42 in this language. If an inline handler function is provided by the
43 language, declare it with a command like
44 CREATE FUNCTION inline_function_name(internal)
46 AS 'path-to-shared-object'
49 4. Optionally, the language handler can provide a “validator” function
50 that checks a function definition for correctness without actually
51 executing it. The validator function is called by CREATE FUNCTION
52 if it exists. If a validator function is provided by the language,
53 declare it with a command like
54 CREATE FUNCTION validator_function_name(oid)
56 AS 'path-to-shared-object'
59 5. Finally, the PL must be declared with the command
60 CREATE [TRUSTED] LANGUAGE language_name
61 HANDLER handler_function_name
62 [INLINE inline_function_name]
63 [VALIDATOR validator_function_name] ;
65 The optional key word TRUSTED specifies that the language does not
66 grant access to data that the user would not otherwise have.
67 Trusted languages are designed for ordinary database users (those
68 without superuser privilege) and allows them to safely create
69 functions and procedures. Since PL functions are executed inside
70 the database server, the TRUSTED flag should only be given for
71 languages that do not allow access to database server internals or
72 the file system. The languages PL/pgSQL, PL/Tcl, and PL/Perl are
73 considered trusted; the languages PL/TclU, PL/PerlU, and PL/PythonU
74 are designed to provide unlimited functionality and should not be
77 Example 40.1 shows how the manual installation procedure would work
78 with the language PL/Perl.
80 Example 40.1. Manual Installation of PL/Perl
82 The following command tells the database server where to find the
83 shared object for the PL/Perl language's call handler function:
84 CREATE FUNCTION plperl_call_handler() RETURNS language_handler AS
85 '$libdir/plperl' LANGUAGE C;
87 PL/Perl has an inline handler function and a validator function, so we
89 CREATE FUNCTION plperl_inline_handler(internal) RETURNS void AS
90 '$libdir/plperl' LANGUAGE C STRICT;
92 CREATE FUNCTION plperl_validator(oid) RETURNS void AS
93 '$libdir/plperl' LANGUAGE C STRICT;
96 CREATE TRUSTED LANGUAGE plperl
97 HANDLER plperl_call_handler
98 INLINE plperl_inline_handler
99 VALIDATOR plperl_validator;
101 then defines that the previously declared functions should be invoked
102 for functions and procedures where the language attribute is plperl.
104 In a default PostgreSQL installation, the handler for the PL/pgSQL
105 language is built and installed into the “library” directory;
106 furthermore, the PL/pgSQL language itself is installed in all
107 databases. If Tcl support is configured in, the handlers for PL/Tcl and
108 PL/TclU are built and installed in the library directory, but the
109 language itself is not installed in any database by default. Likewise,
110 the PL/Perl and PL/PerlU handlers are built and installed if Perl
111 support is configured, and the PL/PythonU handler is installed if
112 Python support is configured, but these languages are not installed by