2 $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.37 2003/09/22 00:16:57 petere Exp $
3 PostgreSQL documentation
6 <refentry id="SQL-CREATELANGUAGE">
8 <refentrytitle id="sql-createlanguage-title">CREATE LANGUAGE</refentrytitle>
9 <refmiscinfo>SQL - Language Statements</refmiscinfo>
13 <refname>CREATE LANGUAGE</refname>
14 <refpurpose>define a new procedural language</refpurpose>
17 <indexterm zone="sql-createlanguage">
18 <primary>CREATE LANGUAGE</primary>
23 CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>
24 HANDLER <replaceable class="parameter">call_handler</replaceable> [ VALIDATOR <replaceable>valfunction</replaceable> ]
28 <refsect1 id="sql-createlanguage-description">
29 <title>Description</title>
32 Using <command>CREATE LANGUAGE</command>, a
33 <productname>PostgreSQL</productname> user can register a new
34 procedural language with a <productname>PostgreSQL</productname>
35 database. Subsequently, functions and trigger procedures can be
36 defined in this new language. The user must have the
37 <productname>PostgreSQL</productname> superuser privilege to
38 register a new language.
42 <command>CREATE LANGUAGE</command> effectively associates the
43 language name with a call handler that is responsible for executing
44 functions written in the language. Refer to <xref linkend="xfunc">
45 for more information about language call handlers.
49 Note that procedural languages are local to individual databases.
50 To make a language available in all databases by default, it should
51 be installed into the <literal>template1</literal> database.
55 <refsect1 id="sql-createlanguage-parameters">
56 <title>Parameters</title>
60 <term><literal>TRUSTED</literal></term>
64 <literal>TRUSTED</literal> specifies that the call handler for
65 the language is safe, that is, it does not offer an
66 unprivileged user any functionality to bypass access
67 restrictions. If this key word is omitted when registering the
68 language, only users with the
69 <productname>PostgreSQL</productname> superuser privilege can
70 use this language to create new functions.
76 <term><literal>PROCEDURAL</literal></term>
86 <term><replaceable class="parameter">name</replaceable></term>
90 The name of the new procedural language. The language name is
91 case insensitive. The name must be unique among the languages
96 For backward compatibility, the name may be enclosed by single
103 <term><literal>HANDLER</literal> <replaceable class="parameter">call_handler</replaceable></term>
107 <replaceable class="parameter">call_handler</replaceable> is
108 the name of a previously registered function that will be
109 called to execute the procedural language functions. The call
110 handler for a procedural language must be written in a compiled
111 language such as C with version 1 call convention and
112 registered with <productname>PostgreSQL</productname> as a
113 function taking no arguments and returning the
114 <type>language_handler</type> type, a placeholder type that is
115 simply used to identify the function as a call handler.
121 <term><literal>VALIDATOR</literal> <replaceable class="parameter">valfunction</replaceable></term>
125 <replaceable class="parameter">valfunction</replaceable> is the
126 name of a previously registered function that will be called
127 when a new function in the language is created, to validate the
130 validator function is specified, then a new function will not
131 be checked when it is created.
132 The validator function must take one argument of
133 type <type>oid</type>, which will be the OID of the
134 to-be-created function, and will typically return <type>void</>.
138 A validator function would typically inspect the function body
139 for syntactical correctness, but it can also look at other
140 properties of the function, for example if the language cannot
141 handle certain argument types. To signal an error, the
142 validator function should use the <function>ereport()</function>
143 function. The return value of the function is ignored.
150 <refsect1 id="sql-createlanguage-notes">
154 This command normally should not be executed directly by users.
155 For the procedural languages supplied in the
156 <productname>PostgreSQL</productname> distribution, the <xref
157 linkend="app-createlang"> program should be used, which will also
158 install the correct call handler. (<command>createlang</command>
159 will call <command>CREATE LANGUAGE</command> internally.)
163 In <productname>PostgreSQL</productname> versions before 7.3, it was
164 necessary to declare handler functions as returning the placeholder
165 type <type>opaque</>, rather than <type>language_handler</>.
167 of old dump files, <command>CREATE LANGUAGE</> will accept a function
168 declared as returning <type>opaque</>, but it will issue a notice and
169 change the function's declared return type to <type>language_handler</>.
173 Use the <xref linkend="sql-createfunction" endterm="sql-createfunction-title"> command to create a new
178 Use <xref linkend="sql-droplanguage" endterm="sql-droplanguage-title">, or better yet the <xref
179 linkend="app-droplang"> program, to drop procedural languages.
183 The system catalog <classname>pg_language</classname> (see <xref
184 linkend="catalog-pg-language">) records information about the
185 currently installed languages. Also <command>createlang</command>
186 has an option to list the installed languages.
190 The definition of a procedural language cannot be changed once it
191 has been created, with the exception of the privileges.
195 To be able to use a procedural language, a user must be granted the
196 <literal>USAGE</literal> privilege. The
197 <command>createlang</command> program automatically grants
198 permissions to everyone if the language is known to be trusted.
202 <refsect1 id="sql-createlanguage-examples">
203 <title>Examples</title>
206 The following two commands executed in sequence will register a new
207 procedural language and the associated call handler.
209 CREATE FUNCTION plsample_call_handler() RETURNS language_handler
210 AS '$libdir/plsample'
212 CREATE LANGUAGE plsample
213 HANDLER plsample_call_handler;
218 <refsect1 id="sql-createlanguage-compat">
219 <title>Compatibility</title>
222 <command>CREATE LANGUAGE</command> is a
223 <productname>PostgreSQL</productname> extension.
228 <title>See Also</title>
230 <simplelist type="inline">
231 <member><xref linkend="sql-alterlanguage" endterm="sql-alterlanguage-title"></member>
232 <member><xref linkend="sql-createfunction" endterm="sql-createfunction-title"></member>
233 <member><xref linkend="sql-droplanguage" endterm="sql-droplanguage-title"></member>
234 <member><xref linkend="sql-grant" endterm="sql-grant-title"></member>
235 <member><xref linkend="sql-revoke" endterm="sql-revoke-title"></member>
236 <member><xref linkend="app-createlang"></member>
237 <member><xref linkend="app-droplang"></member>
242 <!-- Keep this comment at the end of the file
247 sgml-minimize-attributes:nil
248 sgml-always-quote-attributes:t
251 sgml-parent-document:nil
252 sgml-default-dtd-file:"../reference.ced"
253 sgml-exposed-tags:nil
254 sgml-local-catalogs:"/usr/lib/sgml/catalog"
255 sgml-local-ecat-files:nil