1CREATE LANGUAGE() SQL Commands CREATE LANGUAGE()
2
3
4
6 CREATE LANGUAGE - define a new procedural language
7
8
10 CREATE [ PROCEDURAL ] LANGUAGE name
11 CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name
12 HANDLER call_handler [ VALIDATOR valfunction ]
13
14
16 Using CREATE LANGUAGE, a PostgreSQL user can register a new procedural
17 language with a PostgreSQL database. Subsequently, functions and trig‐
18 ger procedures can be defined in this new language. The user must have
19 the PostgreSQL superuser privilege to register a new language.
20
21 CREATE LANGUAGE effectively associates the language name with a call
22 handler that is responsible for executing functions written in the lan‐
23 guage. Refer to in the documentation for more information about lan‐
24 guage call handlers.
25
26 There are two forms of the CREATE LANGUAGE command. In the first form,
27 the user supplies just the name of the desired language, and the Post‐
28 greSQL server consults the pg_pltemplate system catalog to determine
29 the correct parameters. In the second form, the user supplies the lan‐
30 guage parameters along with the language name. The second form can be
31 used to create a language that is not defined in pg_pltemplate, but
32 this approach is considered obsolescent.
33
34 When the server finds an entry in the pg_pltemplate catalog for the
35 given language name, it will use the catalog data even if the command
36 includes language parameters. This behavior simplifies loading of old
37 dump files, which are likely to contain out-of-date information about
38 language support functions.
39
41 TRUSTED
42 TRUSTED specifies that the call handler for the language is
43 safe, that is, it does not offer an unprivileged user any func‐
44 tionality to bypass access restrictions. If this key word is
45 omitted when registering the language, only users with the Post‐
46 greSQL superuser privilege can use this language to create new
47 functions.
48
49 PROCEDURAL
50 This is a noise word.
51
52 name The name of the new procedural language. The language name is
53 case insensitive. The name must be unique among the languages in
54 the database.
55
56 For backward compatibility, the name may be enclosed by single
57 quotes.
58
59 HANDLER call_handler
60 call_handler is the name of a previously registered function
61 that will be called to execute the procedural language func‐
62 tions. The call handler for a procedural language must be writ‐
63 ten in a compiled language such as C with version 1 call conven‐
64 tion and registered with PostgreSQL as a function taking no
65 arguments and returning the language_handler type, a placeholder
66 type that is simply used to identify the function as a call han‐
67 dler.
68
69 VALIDATOR valfunction
70 valfunction is the name of a previously registered function that
71 will be called when a new function in the language is created,
72 to validate the new function. If no validator function is spec‐
73 ified, then a new function will not be checked when it is cre‐
74 ated. The validator function must take one argument of type
75 oid, which will be the OID of the to-be-created function, and
76 will typically return void.
77
78 A validator function would typically inspect the function body
79 for syntactical correctness, but it can also look at other prop‐
80 erties of the function, for example if the language cannot han‐
81 dle certain argument types. To signal an error, the validator
82 function should use the ereport() function. The return value of
83 the function is ignored.
84
85 The TRUSTED option and the support function name(s) are ignored if the
86 server has an entry for the specified language name in pg_pltemplate.
87
89 The createlang(1) program is a simple wrapper around the CREATE LAN‐
90 GUAGE command. It eases installation of procedural languages from the
91 shell command line.
92
93 Use DROP LANGUAGE [drop_language(7)], or better yet the droplang(1)
94 program, to drop procedural languages.
95
96 The system catalog pg_language (see in the documentation) records
97 information about the currently installed languages. Also, createlang
98 has an option to list the installed languages.
99
100 To create functions in a procedural language, a user must have the
101 USAGE privilege for the language. By default, USAGE is granted to PUB‐
102 LIC (i.e., everyone) for trusted languages. This may be revoked if
103 desired.
104
105 Procedural languages are local to individual databases. However, a
106 language can be installed into the template1 database, which will cause
107 it to be available automatically in all subsequently-created databases.
108
109 The call handler function and the validator function (if any) must
110 already exist if the server does not have an entry for the language in
111 pg_pltemplate. But when there is an entry, the functions need not
112 already exist; they will be automatically defined if not present in the
113 database. (This can result in CREATE LANGUAGE failing, if the shared
114 library that implements the language is not available in the installa‐
115 tion.)
116
117 In PostgreSQL versions before 7.3, it was necessary to declare handler
118 functions as returning the placeholder type opaque, rather than lan‐
119 guage_handler. To support loading of old dump files, CREATE LANGUAGE
120 will accept a function declared as returning opaque, but it will issue
121 a notice and change the function's declared return type to lan‐
122 guage_handler.
123
125 The preferred way of creating any of the standard procedural languages
126 is just:
127
128 CREATE LANGUAGE plpgsql;
129
130
131 For a language not known in the pg_pltemplate catalog, a sequence such
132 as this is needed:
133
134 CREATE FUNCTION plsample_call_handler() RETURNS language_handler
135 AS '$libdir/plsample'
136 LANGUAGE C;
137 CREATE LANGUAGE plsample
138 HANDLER plsample_call_handler;
139
140
142 CREATE LANGUAGE is a PostgreSQL extension.
143
145 ALTER LANGUAGE [alter_language(7)], CREATE FUNCTION [create_func‐
146 tion(l)], DROP LANGUAGE [drop_language(l)], GRANT [grant(l)], REVOKE
147 [revoke(l)], createlang [createlang(1)], droplang [droplang(1)]
148
149
150
151SQL - Language Statements 2008-06-08 CREATE LANGUAGE()