1CREATE LANGUAGE(7)       PostgreSQL 13.3 Documentation      CREATE LANGUAGE(7)
2
3
4

NAME

6       CREATE_LANGUAGE - define a new procedural language
7

SYNOPSIS

9       CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name
10           HANDLER call_handler [ INLINE inline_handler ] [ VALIDATOR valfunction ]
11       CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name
12

DESCRIPTION

14       CREATE LANGUAGE registers a new procedural language with a PostgreSQL
15       database. Subsequently, functions and procedures can be defined in this
16       new language.
17
18       CREATE LANGUAGE effectively associates the language name with handler
19       function(s) that are responsible for executing functions written in the
20       language. Refer to Chapter 55 for more information about language
21       handlers.
22
23       CREATE OR REPLACE LANGUAGE will either create a new language, or
24       replace an existing definition. If the language already exists, its
25       parameters are updated according to the command, but the language's
26       ownership and permissions settings do not change, and any existing
27       functions written in the language are assumed to still be valid.
28
29       One must have the PostgreSQL superuser privilege to register a new
30       language or change an existing language's parameters. However, once the
31       language is created it is valid to assign ownership of it to a
32       non-superuser, who may then drop it, change its permissions, rename it,
33       or assign it to a new owner. (Do not, however, assign ownership of the
34       underlying C functions to a non-superuser; that would create a
35       privilege escalation path for that user.)
36
37       The form of CREATE LANGUAGE that does not supply any handler function
38       is obsolete. For backwards compatibility with old dump files, it is
39       interpreted as CREATE EXTENSION. That will work if the language has
40       been packaged into an extension of the same name, which is the
41       conventional way to set up procedural languages.
42

PARAMETERS

44       TRUSTED
45           TRUSTED specifies that the language does not grant access to data
46           that the user would not otherwise have. If this key word is omitted
47           when registering the language, only users with the PostgreSQL
48           superuser privilege can use this language to create new functions.
49
50       PROCEDURAL
51           This is a noise word.
52
53       name
54           The name of the new procedural language. The name must be unique
55           among the languages in the database.
56
57           For backward compatibility, the name can be enclosed by single
58           quotes.
59
60       HANDLER call_handler
61           call_handler is the name of a previously registered function that
62           will be called to execute the procedural language's functions. The
63           call handler for a procedural language must be written in a
64           compiled language such as C with version 1 call convention and
65           registered with PostgreSQL as a function taking no arguments and
66           returning the language_handler type, a placeholder type that is
67           simply used to identify the function as a call handler.
68
69       INLINE inline_handler
70           inline_handler is the name of a previously registered function that
71           will be called to execute an anonymous code block (DO(7) command)
72           in this language. If no inline_handler function is specified, the
73           language does not support anonymous code blocks. The handler
74           function must take one argument of type internal, which will be the
75           DO command's internal representation, and it will typically return
76           void. The return value of the handler is ignored.
77
78       VALIDATOR valfunction
79           valfunction is the name of a previously registered function that
80           will be called when a new function in the language is created, to
81           validate the new function. If no validator function is specified,
82           then a new function will not be checked when it is created. The
83           validator function must take one argument of type oid, which will
84           be the OID of the to-be-created function, and will typically return
85           void.
86
87           A validator function would typically inspect the function body for
88           syntactical correctness, but it can also look at other properties
89           of the function, for example if the language cannot handle certain
90           argument types. To signal an error, the validator function should
91           use the ereport() function. The return value of the function is
92           ignored.
93

NOTES

95       Use DROP LANGUAGE (DROP_LANGUAGE(7)) to drop procedural languages.
96
97       The system catalog pg_language (see Section 51.29) records information
98       about the currently installed languages. Also, the psql command \dL
99       lists the installed languages.
100
101       To create functions in a procedural language, a user must have the
102       USAGE privilege for the language. By default, USAGE is granted to
103       PUBLIC (i.e., everyone) for trusted languages. This can be revoked if
104       desired.
105
106       Procedural languages are local to individual databases. However, a
107       language can be installed into the template1 database, which will cause
108       it to be available automatically in all subsequently-created databases.
109

EXAMPLES

111       A minimal sequence for creating a new procedural language is:
112
113           CREATE FUNCTION plsample_call_handler() RETURNS language_handler
114               AS '$libdir/plsample'
115               LANGUAGE C;
116           CREATE LANGUAGE plsample
117               HANDLER plsample_call_handler;
118
119       Typically that would be written in an extension's creation script, and
120       users would do this to install the extension:
121
122           CREATE EXTENSION plsample;
123

COMPATIBILITY

125       CREATE LANGUAGE is a PostgreSQL extension.
126

SEE ALSO

128       ALTER LANGUAGE (ALTER_LANGUAGE(7)), CREATE FUNCTION
129       (CREATE_FUNCTION(7)), DROP LANGUAGE (DROP_LANGUAGE(7)), GRANT(7),
130       REVOKE(7)
131
132
133
134PostgreSQL 13.3                      2021                   CREATE LANGUAGE(7)
Impressum