1CREATE LANGUAGE(7) PostgreSQL 9.2.24 Documentation CREATE LANGUAGE(7)
2
3
4
6 CREATE_LANGUAGE - define a new procedural language
7
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
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 49, Writing A Procedural Language Handler,
30 in the documentation for more information about language 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
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
124 The createlang(1) program is a simple wrapper around the CREATE
125 LANGUAGE command. It eases installation of procedural languages from
126 the shell command line.
127
128 Use DROP LANGUAGE (DROP_LANGUAGE(7)), or better yet the droplang(1)
129 program, to drop procedural languages.
130
131 The system catalog pg_language (see Section 45.27, “pg_language”, in
132 the documentation) records information about the currently installed
133 languages. Also, createlang has an option to list the installed
134 languages.
135
136 To create functions in a procedural language, a user must have the
137 USAGE privilege for the language. By default, USAGE is granted to
138 PUBLIC (i.e., everyone) for trusted languages. This can be revoked if
139 desired.
140
141 Procedural languages are local to individual databases. However, a
142 language can be installed into the template1 database, which will cause
143 it to be available automatically in all subsequently-created databases.
144
145 The call handler function, the inline handler function (if any), and
146 the validator function (if any) must already exist if the server does
147 not have an entry for the language in pg_pltemplate. But when there is
148 an entry, the functions need not already exist; they will be
149 automatically defined if not present in the database. (This might
150 result in CREATE LANGUAGE failing, if the shared library that
151 implements the language is not available in the installation.)
152
153 In PostgreSQL versions before 7.3, it was necessary to declare handler
154 functions as returning the placeholder type opaque, rather than
155 language_handler. To support loading of old dump files, CREATE LANGUAGE
156 will accept a function declared as returning opaque, but it will issue
157 a notice and change the function's declared return type to
158 language_handler.
159
161 The preferred way of creating any of the standard procedural languages
162 is just:
163
164 CREATE LANGUAGE plperl;
165
166 For a language not known in the pg_pltemplate catalog, a sequence such
167 as this is needed:
168
169 CREATE FUNCTION plsample_call_handler() RETURNS language_handler
170 AS '$libdir/plsample'
171 LANGUAGE C;
172 CREATE LANGUAGE plsample
173 HANDLER plsample_call_handler;
174
176 CREATE LANGUAGE is a PostgreSQL extension.
177
179 ALTER LANGUAGE (ALTER_LANGUAGE(7)), CREATE FUNCTION
180 (CREATE_FUNCTION(7)), DROP LANGUAGE (DROP_LANGUAGE(7)), GRANT(7),
181 REVOKE(7), createlang(1), droplang(1)
182
183
184
185PostgreSQL 9.2.24 2017-11-06 CREATE LANGUAGE(7)