1999-07-22 15:09:15 +00:00
|
|
|
<!--
|
2002-04-21 19:02:39 +00:00
|
|
|
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.22 2002/04/21 19:02:39 thomas Exp $
|
2001-12-08 03:24:40 +00:00
|
|
|
PostgreSQL documentation
|
1999-07-22 15:09:15 +00:00
|
|
|
-->
|
|
|
|
|
1999-07-06 17:16:42 +00:00
|
|
|
<refentry id="SQL-CREATELANGUAGE">
|
|
|
|
<refmeta>
|
2001-09-06 10:28:39 +00:00
|
|
|
<refentrytitle id="sql-createlanguage-title">CREATE LANGUAGE</refentrytitle>
|
1999-07-06 17:16:42 +00:00
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
2001-09-06 10:28:39 +00:00
|
|
|
|
1999-07-06 17:16:42 +00:00
|
|
|
<refnamediv>
|
2001-09-06 10:28:39 +00:00
|
|
|
<refname>CREATE LANGUAGE</refname>
|
|
|
|
<refpurpose>define a new procedural language</refpurpose>
|
1998-12-29 02:24:47 +00:00
|
|
|
</refnamediv>
|
2001-09-06 10:28:39 +00:00
|
|
|
|
1999-07-06 17:16:42 +00:00
|
|
|
<refsynopsisdiv>
|
2001-09-06 10:28:39 +00:00
|
|
|
<synopsis>
|
2001-08-13 21:34:54 +00:00
|
|
|
CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">langname</replaceable>
|
1998-09-16 14:43:12 +00:00
|
|
|
HANDLER <replaceable class="parameter">call_handler</replaceable>
|
2001-09-06 10:28:39 +00:00
|
|
|
</synopsis>
|
1999-07-06 17:16:42 +00:00
|
|
|
</refsynopsisdiv>
|
|
|
|
|
2001-09-06 10:28:39 +00:00
|
|
|
<refsect1 id="sql-createlanguage-description">
|
|
|
|
<title>Description</title>
|
|
|
|
|
1999-07-06 17:16:42 +00:00
|
|
|
<para>
|
2001-09-06 10:28:39 +00:00
|
|
|
Using <command>CREATE LANGUAGE</command>, a
|
|
|
|
<productname>PostgreSQL</productname> user can register a new
|
|
|
|
procedural language with a <productname>PostgreSQL</productname>
|
|
|
|
database. Subsequently, functions and trigger procedures can be
|
|
|
|
defined in this new language. The user must have the
|
|
|
|
<productname>PostgreSQL</productname> superuser privilege to
|
1998-05-13 05:34:00 +00:00
|
|
|
register a new language.
|
1999-07-06 17:16:42 +00:00
|
|
|
</para>
|
|
|
|
|
2001-09-06 10:28:39 +00:00
|
|
|
<para>
|
|
|
|
<command>CREATE LANGUAGE</command> effectively associates the
|
|
|
|
language name with a call handler that is responsible for executing
|
|
|
|
functions written in the language. Refer to the
|
|
|
|
<citetitle>Programmer's Guide</citetitle> for more information
|
|
|
|
about language call handlers.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Note that procedural languages are local to individual databases.
|
|
|
|
To make a language available in all databases by default, it should
|
|
|
|
be installed into the <literal>template1</literal> database.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 id="sql-createlanguage-parameters">
|
|
|
|
<title>Parameters</title>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>TRUSTED</literal></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>TRUSTED</literal> specifies that the call handler for
|
|
|
|
the language is safe, that is, it does not offer an
|
|
|
|
unprivileged user any functionality to bypass access
|
|
|
|
restrictions. If this keyword is omitted when registering the
|
|
|
|
language, only users with the
|
|
|
|
<productname>PostgreSQL</productname> superuser privilege can
|
|
|
|
use this language to create new functions.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>PROCEDURAL</literal></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This is a noise word.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2000-05-29 01:59:17 +00:00
|
|
|
|
2001-09-06 10:28:39 +00:00
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">langname</replaceable></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The name of the new procedural language. The language name is
|
|
|
|
case insensitive. A procedural language cannot override one of
|
|
|
|
the built-in languages of <productname>PostgreSQL</productname>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
For backward compatibility, the name may be enclosed by single
|
|
|
|
quotes.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>HANDLER</literal> <replaceable class="parameter">call_handler</replaceable></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<replaceable class="parameter">call_handler</replaceable> is
|
|
|
|
the name of a previously registered function that will be
|
|
|
|
called to execute the procedural language functions. The call
|
|
|
|
handler for a procedural language must be written in a compiled
|
|
|
|
language such as C with version 1 call convention and
|
|
|
|
registered with <productname>PostgreSQL</productname> as a
|
|
|
|
function taking no arguments and returning the
|
|
|
|
<type>opaque</type> type, a placeholder for unspecified or
|
|
|
|
undefined types.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 id="sql-createlanguage-diagnostics">
|
|
|
|
<title>Diagnostics</title>
|
|
|
|
|
|
|
|
<msgset>
|
|
|
|
<msgentry>
|
|
|
|
<msg>
|
|
|
|
<msgmain>
|
|
|
|
<msgtext>
|
|
|
|
<screen>
|
|
|
|
CREATE
|
|
|
|
</screen>
|
|
|
|
</msgtext>
|
|
|
|
</msgmain>
|
|
|
|
</msg>
|
|
|
|
|
|
|
|
<msgexplan>
|
2000-05-29 01:59:17 +00:00
|
|
|
<para>
|
2001-09-06 10:28:39 +00:00
|
|
|
This message is returned if the language is successfully
|
|
|
|
created.
|
2000-05-29 01:59:17 +00:00
|
|
|
</para>
|
2001-09-06 10:28:39 +00:00
|
|
|
</msgexplan>
|
|
|
|
</msgentry>
|
|
|
|
|
|
|
|
<msgentry>
|
|
|
|
<msg>
|
|
|
|
<msgmain>
|
|
|
|
<msgtext>
|
|
|
|
<screen>
|
|
|
|
ERROR: PL handler function <replaceable class="parameter">funcname</replaceable>() doesn't exist
|
|
|
|
</screen>
|
|
|
|
</msgtext>
|
|
|
|
</msgmain>
|
|
|
|
</msg>
|
|
|
|
|
|
|
|
<msgexplan>
|
|
|
|
<para>
|
|
|
|
This error is returned if the function <replaceable
|
|
|
|
class="parameter">funcname</replaceable>() is not found.
|
|
|
|
</para>
|
|
|
|
</msgexplan>
|
|
|
|
</msgentry>
|
|
|
|
</msgset>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 id="sql-createlanguage-notes">
|
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
This command normally should not be executed directly by users.
|
|
|
|
For the procedural languages supplied in the
|
|
|
|
<productname>PostgreSQL</productname> distribution, the <xref
|
2001-10-26 21:17:03 +00:00
|
|
|
linkend="app-createlang"> script should be used, which will also
|
2001-09-06 10:28:39 +00:00
|
|
|
install the correct call handler. (<command>createlang</command>
|
|
|
|
will call <command>CREATE LANGUAGE</command> internally.)
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-11-18 20:35:02 +00:00
|
|
|
Use the <xref linkend="sql-createfunction" endterm="sql-createfunction-title"> command to create a new
|
2001-09-06 10:28:39 +00:00
|
|
|
function.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-11-18 20:35:02 +00:00
|
|
|
Use <xref linkend="sql-droplanguage" endterm="sql-droplanguage-title">, or better yet the <xref
|
2001-10-26 21:17:03 +00:00
|
|
|
linkend="app-droplang"> script, to drop procedural languages.
|
2001-09-06 10:28:39 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The system catalog <classname>pg_language</classname> records
|
|
|
|
information about the currently installed procedural languages.
|
|
|
|
|
|
|
|
<screen>
|
2000-03-26 18:32:30 +00:00
|
|
|
Table "pg_language"
|
|
|
|
Attribute | Type | Modifier
|
|
|
|
---------------+---------+----------
|
|
|
|
lanname | name |
|
|
|
|
lanispl | boolean |
|
|
|
|
lanpltrusted | boolean |
|
|
|
|
lanplcallfoid | oid |
|
|
|
|
lancompiler | text |
|
1998-09-16 14:43:12 +00:00
|
|
|
|
2000-08-24 23:36:29 +00:00
|
|
|
lanname | lanispl | lanpltrusted | lanplcallfoid | lancompiler
|
|
|
|
-------------+---------+--------------+---------------+-------------
|
|
|
|
internal | f | f | 0 | n/a
|
2002-02-18 23:11:58 +00:00
|
|
|
c | f | f | 0 | /bin/cc
|
|
|
|
sql | f | t | 0 | postgres
|
2001-09-06 10:28:39 +00:00
|
|
|
</screen>
|
1999-07-06 17:16:42 +00:00
|
|
|
</para>
|
1998-05-13 05:34:00 +00:00
|
|
|
|
|
|
|
<para>
|
2001-09-06 10:28:39 +00:00
|
|
|
At present, the definition of a procedural language cannot be
|
2001-10-26 21:17:03 +00:00
|
|
|
changed once it has been created.
|
1999-07-06 17:16:42 +00:00
|
|
|
</para>
|
2002-02-18 23:11:58 +00:00
|
|
|
|
|
|
|
<para>
|
|
|
|
To be able to use a procedural language, a user must be granted the
|
|
|
|
<literal>USAGE</literal> privilege. The
|
|
|
|
<command>createlang</command> program automatically grants
|
|
|
|
permissions to everyone if the language is known to be trusted.
|
|
|
|
</para>
|
2001-09-06 10:28:39 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 id="sql-createlanguage-examples">
|
|
|
|
<title>Examples</title>
|
|
|
|
|
1998-05-13 05:34:00 +00:00
|
|
|
<para>
|
2001-09-06 10:28:39 +00:00
|
|
|
The following two commands executed in sequence will register a new
|
|
|
|
procedural language and the associated call handler.
|
|
|
|
<programlisting>
|
1999-07-06 17:16:42 +00:00
|
|
|
CREATE FUNCTION plsample_call_handler () RETURNS opaque
|
2001-10-26 21:17:03 +00:00
|
|
|
AS '$libdir/plsample'
|
2001-08-13 21:34:54 +00:00
|
|
|
LANGUAGE C;
|
|
|
|
CREATE LANGUAGE plsample
|
|
|
|
HANDLER plsample_call_handler;
|
2001-09-06 10:28:39 +00:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 id="sql-createlanguage-compat">
|
|
|
|
<title>Compatibility</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<command>CREATE LANGUAGE</command> is a
|
|
|
|
<productname>PostgreSQL</productname> extension.
|
1998-12-29 02:24:47 +00:00
|
|
|
</para>
|
1999-07-06 17:16:42 +00:00
|
|
|
</refsect1>
|
|
|
|
|
2001-09-06 10:28:39 +00:00
|
|
|
<refsect1>
|
|
|
|
<title>History</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <command>CREATE LANGUAGE</command> command first appeared in
|
|
|
|
<productname>PostgreSQL</productname> 6.3.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>See Also</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<simplelist type="inline">
|
|
|
|
<member><xref linkend="app-createlang"></member>
|
|
|
|
<member><xref linkend="sql-createfunction"></member>
|
|
|
|
<member><xref linkend="app-droplang"></member>
|
|
|
|
<member><xref linkend="sql-droplanguage"></member>
|
2002-02-18 23:11:58 +00:00
|
|
|
<member><xref linkend="sql-grant"></member>
|
|
|
|
<member><xref linkend="sql-revoke"></member>
|
2001-09-06 10:28:39 +00:00
|
|
|
<member><citetitle>PostgreSQL Programmer's Guide</citetitle></member>
|
|
|
|
</simplelist>
|
|
|
|
</para>
|
1998-05-13 05:34:00 +00:00
|
|
|
</refsect1>
|
1999-07-06 17:16:42 +00:00
|
|
|
</refentry>
|
1998-05-13 05:34:00 +00:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
1999-07-06 17:16:42 +00:00
|
|
|
sgml-omittag:nil
|
1998-05-13 05:34:00 +00:00
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../reference.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:"/usr/lib/sgml/catalog"
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
-->
|