11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/ref/create_language.sgml,v 1.39 2005/01/04 00:39:53 tgl Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/ref/create_language.sgml,v 1.40 2005/09/05 23:50:48 tgl Exp $
33PostgreSQL documentation
44-->
55
@@ -20,6 +20,7 @@ PostgreSQL documentation
2020
2121 <refsynopsisdiv>
2222<synopsis>
23+ CREATE [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>
2324CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>
2425 HANDLER <replaceable class="parameter">call_handler</replaceable> [ VALIDATOR <replaceable>valfunction</replaceable> ]
2526</synopsis>
@@ -46,9 +47,25 @@ CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</
4647 </para>
4748
4849 <para>
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.
50+ There are two forms of the <command>CREATE LANGUAGE</command> command.
51+ In the first form, the user merely supplies the name of the desired
52+ language, and the <productname>PostgreSQL</productname> server consults
53+ an internal table to determine the correct parameters. In
54+ the second form, the user supplies the language parameters along with
55+ the language name. The second form must be used to create a language
56+ that is not present in the internal table, but this form is considered
57+ obsolescent. (It is expected that future releases of
58+ <productname>PostgreSQL</productname> will replace the internal table
59+ with a system catalog that can be extended to support additional
60+ languages.)
61+ </para>
62+
63+ <para>
64+ When the server finds an entry in its internal table for the given
65+ language name, it will use the table data even if the given command
66+ includes language parameters. This behavior simplifies loading of
67+ old dump files, which are likely to contain out-of-date information
68+ about language support functions.
5269 </para>
5370 </refsect1>
5471
@@ -145,61 +162,85 @@ CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</
145162 </listitem>
146163 </varlistentry>
147164 </variablelist>
165+
166+ <para>
167+ The <literal>TRUSTED</> option and the support function name(s) are
168+ ignored if the server has information about the specified language
169+ name in its internal table.
170+ </para>
148171 </refsect1>
149172
150173 <refsect1 id="sql-createlanguage-notes">
151174 <title>Notes</title>
152175
153176 <para>
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.)
177+ The <xref linkend="app-createlang"> program is a simple wrapper around
178+ the <command>CREATE LANGUAGE</> command. It eases
179+ installation of procedural languages from the shell command line.
160180 </para>
161181
162182 <para>
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</>.
166- To support loading
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</>.
183+ Use <xref linkend="sql-droplanguage" endterm="sql-droplanguage-title">, or better yet the <xref
184+ linkend="app-droplang"> program, to drop procedural languages.
170185 </para>
171186
172187 <para>
173- Use the <xref linkend="sql-createfunction" endterm="sql-createfunction-title"> command to create a new
174- function.
188+ The system catalog <classname>pg_language</classname> (see <xref
189+ linkend="catalog-pg-language">) records information about the
190+ currently installed languages. Also, <command>createlang</command>
191+ has an option to list the installed languages.
175192 </para>
176193
177194 <para>
178- Use <xref linkend="sql-droplanguage" endterm="sql-droplanguage-title">, or better yet the <xref
179- linkend="app-droplang"> program, to drop procedural languages.
195+ To create functions in a procedural language, a user must have the
196+ <literal>USAGE</literal> privilege for the language. By default,
197+ <literal>USAGE</> is granted to <literal>PUBLIC</> (i.e., everyone)
198+ for trusted languages. This may be revoked if desired.
180199 </para>
181200
182201 <para>
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 .
202+ Procedural languages are local to individual databases.
203+ However, a language can be installed into the <literal>template1</literal>
204+ database, which will cause it to be available automatically in
205+ all subsequently-created databases .
187206 </para>
188207
189208 <para>
190- To be able to use a procedural language, a user must be granted the
191- <literal>USAGE</literal> privilege. The
192- <command>createlang</command> program automatically grants
193- permissions to everyone if the language is known to be trusted.
209+ The call handler function and the validator function (if any)
210+ must already exist if the server does not have information about
211+ the language in its internal table. But when there is an entry
212+ in the internal table, the functions need not already exist;
213+ they will be automatically defined if not present in the database.
214+ (This can result in <command>CREATE LANGUAGE</> failing, if the
215+ shared library that implements the language is not available in
216+ the installation.)
217+ </para>
218+
219+ <para>
220+ In <productname>PostgreSQL</productname> versions before 7.3, it was
221+ necessary to declare handler functions as returning the placeholder
222+ type <type>opaque</>, rather than <type>language_handler</>.
223+ To support loading
224+ of old dump files, <command>CREATE LANGUAGE</> will accept a function
225+ declared as returning <type>opaque</>, but it will issue a notice and
226+ change the function's declared return type to <type>language_handler</>.
194227 </para>
195228 </refsect1>
196229
197230 <refsect1 id="sql-createlanguage-examples">
198231 <title>Examples</title>
199232
200233 <para>
201- The following two commands executed in sequence will register a new
202- procedural language and the associated call handler.
234+ The preferred way of creating any of the standard procedural languages
235+ is just:
236+ <programlisting>
237+ CREATE LANGUAGE plpgsql;
238+ </programlisting>
239+ </para>
240+
241+ <para>
242+ For a language not known in the server's internal table, a sequence
243+ such as this is needed:
203244<programlisting>
204245CREATE FUNCTION plsample_call_handler() RETURNS language_handler
205246 AS '$libdir/plsample'