1CREATE LANGUAGE(7)       PostgreSQL 15.4 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 58 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       HANDLER call_handler
58           call_handler is the name of a previously registered function that
59           will be called to execute the procedural language's functions. The
60           call handler for a procedural language must be written in a
61           compiled language such as C with version 1 call convention and
62           registered with PostgreSQL as a function taking no arguments and
63           returning the language_handler type, a placeholder type that is
64           simply used to identify the function as a call handler.
65
66       INLINE inline_handler
67           inline_handler is the name of a previously registered function that
68           will be called to execute an anonymous code block (DO command) in
69           this language. If no inline_handler function is specified, the
70           language does not support anonymous code blocks. The handler
71           function must take one argument of type internal, which will be the
72           DO command's internal representation, and it will typically return
73           void. The return value of the handler is ignored.
74
75       VALIDATOR valfunction
76           valfunction is the name of a previously registered function that
77           will be called when a new function in the language is created, to
78           validate the new function. If no validator function is specified,
79           then a new function will not be checked when it is created. The
80           validator function must take one argument of type oid, which will
81           be the OID of the to-be-created function, and will typically return
82           void.
83
84           A validator function would typically inspect the function body for
85           syntactical correctness, but it can also look at other properties
86           of the function, for example if the language cannot handle certain
87           argument types. To signal an error, the validator function should
88           use the ereport() function. The return value of the function is
89           ignored.
90

NOTES

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

EXAMPLES

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

COMPATIBILITY

122       CREATE LANGUAGE is a PostgreSQL extension.
123

SEE ALSO

125       ALTER LANGUAGE (ALTER_LANGUAGE(7)), CREATE FUNCTION
126       (CREATE_FUNCTION(7)), DROP LANGUAGE (DROP_LANGUAGE(7)), GRANT(7),
127       REVOKE(7)
128
129
130
131PostgreSQL 15.4                      2023                   CREATE LANGUAGE(7)
Impressum