aboutsummaryrefslogtreecommitdiff
path: root/doc/src/sgml/ref/create_language.sgml
blob: 3d2b71198fcaa5a6fd7d73241a1c8c94a5465fcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_language.sgml,v 1.20 2001/12/08 03:24:34 thomas Exp $
PostgreSQL documentation
-->

<refentry id="SQL-CREATELANGUAGE">
 <docinfo>
  <date>2001-09-05</date>
 </docinfo>

 <refmeta>
  <refentrytitle id="sql-createlanguage-title">CREATE LANGUAGE</refentrytitle>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>CREATE LANGUAGE</refname>
  <refpurpose>define a new procedural language</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">langname</replaceable>
    HANDLER <replaceable class="parameter">call_handler</replaceable>
</synopsis>
 </refsynopsisdiv>

 <refsect1 id="sql-createlanguage-description">
  <title>Description</title>

  <para>
   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
   register a new language.
  </para>

  <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>

    <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>
     <para>
      This message is returned if the language is successfully
      created.
     </para>
    </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
   linkend="app-createlang"> script should be used, which will also
   install the correct call handler.  (<command>createlang</command>
   will call <command>CREATE LANGUAGE</command> internally.)
  </para>

  <para>
   Use the <xref linkend="sql-createfunction" endterm="sql-createfunction-title"> command to create a new
   function.
  </para>

  <para>
   Use <xref linkend="sql-droplanguage" endterm="sql-droplanguage-title">, or better yet the <xref
   linkend="app-droplang"> script, to drop procedural languages.
  </para>

  <para>
   The system catalog <classname>pg_language</classname> records
   information about the currently installed procedural languages.

<screen>
        Table "pg_language"
   Attribute   |  Type   | Modifier
---------------+---------+----------
 lanname       | name    |
 lanispl       | boolean |
 lanpltrusted  | boolean |
 lanplcallfoid | oid     |
 lancompiler   | text    |

   lanname   | lanispl | lanpltrusted | lanplcallfoid | lancompiler
-------------+---------+--------------+---------------+-------------
 internal    | f       | f            |             0 | n/a
 C           | f       | f            |             0 | /bin/cc
 sql         | f       | f            |             0 | postgres
</screen>
  </para>

  <para>
   At present, the definition of a procedural language cannot be
   changed once it has been created.
  </para>
 </refsect1>

 <refsect1 id="sql-createlanguage-examples">
  <title>Examples</title>

  <para>
   The following two commands executed in sequence will register a new
   procedural language and the associated call handler.
<programlisting>
CREATE FUNCTION plsample_call_handler () RETURNS opaque
    AS '$libdir/plsample'
    LANGUAGE C;
CREATE LANGUAGE plsample
    HANDLER plsample_call_handler;
</programlisting>
  </para>
 </refsect1>

 <refsect1 id="sql-createlanguage-compat">
  <title>Compatibility</title>

  <para>
   <command>CREATE LANGUAGE</command> is a
   <productname>PostgreSQL</productname> extension.
  </para>
 </refsect1>

 <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>
    <member><citetitle>PostgreSQL Programmer's Guide</citetitle></member>
   </simplelist>
  </para>
 </refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
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:
-->