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

NAME

6       CREATE_LANGUAGE - define a new procedural language
7

SYNOPSIS

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

DESCRIPTION

14       CREATE LANGUAGE registers a new procedural language with a PostgreSQL
15       database. Subsequently, functions and trigger procedures can be defined
16       in this new language.
17
18           Note
19           As of PostgreSQL 9.1, most procedural languages have been made into
20           “extensions”, and should therefore be installed with CREATE
21           EXTENSION (CREATE_EXTENSION(7)) not CREATE LANGUAGE. Direct use of
22           CREATE LANGUAGE should now be confined to extension installation
23           scripts. If you have a “bare” language in your database, perhaps as
24           a result of an upgrade, you can convert it to an extension using
25           CREATE EXTENSION langname FROM unpackaged.
26
27       CREATE LANGUAGE effectively associates the language name with handler
28       function(s) that are responsible for executing functions written in the
29       language. Refer to Chapter 55 for more information about language
30       handlers.
31
32       There are two forms of the CREATE LANGUAGE command. In the first form,
33       the user supplies just the name of the desired language, and the
34       PostgreSQL server consults the pg_pltemplate system catalog to
35       determine the correct parameters. In the second form, the user supplies
36       the language parameters along with the language name. The second form
37       can be used to create a language that is not defined in pg_pltemplate,
38       but this approach is considered obsolescent.
39
40       When the server finds an entry in the pg_pltemplate catalog for the
41       given language name, it will use the catalog data even if the command
42       includes language parameters. This behavior simplifies loading of old
43       dump files, which are likely to contain out-of-date information about
44       language support functions.
45
46       Ordinarily, the user must have the PostgreSQL superuser privilege to
47       register a new language. However, the owner of a database can register
48       a new language within that database if the language is listed in the
49       pg_pltemplate catalog and is marked as allowed to be created by
50       database owners (tmpldbacreate is true). The default is that trusted
51       languages can be created by database owners, but this can be adjusted
52       by superusers by modifying the contents of pg_pltemplate. The creator
53       of a language becomes its owner and can later drop it, rename it, or
54       assign it to a new owner.
55
56       CREATE OR REPLACE LANGUAGE will either create a new language, or
57       replace an existing definition. If the language already exists, its
58       parameters are updated according to the values specified or taken from
59       pg_pltemplate, but the language's ownership and permissions settings do
60       not change, and any existing functions written in the language are
61       assumed to still be valid. In addition to the normal privilege
62       requirements for creating a language, the user must be superuser or
63       owner of the existing language. The REPLACE case is mainly meant to be
64       used to ensure that the language exists. If the language has a
65       pg_pltemplate entry then REPLACE will not actually change anything
66       about an existing definition, except in the unusual case where the
67       pg_pltemplate entry has been modified since the language was created.
68

PARAMETERS

70       TRUSTED
71           TRUSTED specifies that the language does not grant access to data
72           that the user would not otherwise have. If this key word is omitted
73           when registering the language, only users with the PostgreSQL
74           superuser privilege can use this language to create new functions.
75
76       PROCEDURAL
77           This is a noise word.
78
79       name
80           The name of the new procedural language. The name must be unique
81           among the languages in the database.
82
83           For backward compatibility, the name can be enclosed by single
84           quotes.
85
86       HANDLER call_handler
87           call_handler is the name of a previously registered function that
88           will be called to execute the procedural language's functions. The
89           call handler for a procedural language must be written in a
90           compiled language such as C with version 1 call convention and
91           registered with PostgreSQL as a function taking no arguments and
92           returning the language_handler type, a placeholder type that is
93           simply used to identify the function as a call handler.
94
95       INLINE inline_handler
96           inline_handler is the name of a previously registered function that
97           will be called to execute an anonymous code block (DO(7) command)
98           in this language. If no inline_handler function is specified, the
99           language does not support anonymous code blocks. The handler
100           function must take one argument of type internal, which will be the
101           DO command's internal representation, and it will typically return
102           void. The return value of the handler is ignored.
103
104       VALIDATOR valfunction
105           valfunction is the name of a previously registered function that
106           will be called when a new function in the language is created, to
107           validate the new function. If no validator function is specified,
108           then a new function will not be checked when it is created. The
109           validator function must take one argument of type oid, which will
110           be the OID of the to-be-created function, and will typically return
111           void.
112
113           A validator function would typically inspect the function body for
114           syntactical correctness, but it can also look at other properties
115           of the function, for example if the language cannot handle certain
116           argument types. To signal an error, the validator function should
117           use the ereport() function. The return value of the function is
118           ignored.
119
120       The TRUSTED option and the support function name(s) are ignored if the
121       server has an entry for the specified language name in pg_pltemplate.
122

NOTES

124       Use DROP LANGUAGE (DROP_LANGUAGE(7)) to drop procedural languages.
125
126       The system catalog pg_language (see Section 51.29) records information
127       about the currently installed languages. Also, the psql command \dL
128       lists the installed languages.
129
130       To create functions in a procedural language, a user must have the
131       USAGE privilege for the language. By default, USAGE is granted to
132       PUBLIC (i.e., everyone) for trusted languages. This can be revoked if
133       desired.
134
135       Procedural languages are local to individual databases. However, a
136       language can be installed into the template1 database, which will cause
137       it to be available automatically in all subsequently-created databases.
138
139       The call handler function, the inline handler function (if any), and
140       the validator function (if any) must already exist if the server does
141       not have an entry for the language in pg_pltemplate. But when there is
142       an entry, the functions need not already exist; they will be
143       automatically defined if not present in the database. (This might
144       result in CREATE LANGUAGE failing, if the shared library that
145       implements the language is not available in the installation.)
146
147       In PostgreSQL versions before 7.3, it was necessary to declare handler
148       functions as returning the placeholder type opaque, rather than
149       language_handler. To support loading of old dump files, CREATE LANGUAGE
150       will accept a function declared as returning opaque, but it will issue
151       a notice and change the function's declared return type to
152       language_handler.
153

EXAMPLES

155       The preferred way of creating any of the standard procedural languages
156       is just:
157
158           CREATE LANGUAGE plperl;
159
160       For a language not known in the pg_pltemplate catalog, a sequence such
161       as this is needed:
162
163           CREATE FUNCTION plsample_call_handler() RETURNS language_handler
164               AS '$libdir/plsample'
165               LANGUAGE C;
166           CREATE LANGUAGE plsample
167               HANDLER plsample_call_handler;
168

COMPATIBILITY

170       CREATE LANGUAGE is a PostgreSQL extension.
171

SEE ALSO

173       ALTER LANGUAGE (ALTER_LANGUAGE(7)), CREATE FUNCTION
174       (CREATE_FUNCTION(7)), DROP LANGUAGE (DROP_LANGUAGE(7)), GRANT(7),
175       REVOKE(7)
176
177
178
179PostgreSQL 10.7                      2019                   CREATE LANGUAGE(7)
Impressum