1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>CREATE LANGUAGE</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-createindex.html" title="CREATE INDEX" /><link rel="next" href="sql-creatematerializedview.html" title="CREATE MATERIALIZED VIEW" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">CREATE LANGUAGE</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createindex.html" title="CREATE INDEX">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-creatematerializedview.html" title="CREATE MATERIALIZED VIEW">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-CREATELANGUAGE"><div class="titlepage"></div><a id="id-1.9.3.70.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE LANGUAGE</span></h2><p>CREATE LANGUAGE — define a new procedural language</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <em class="replaceable"><code>name</code></em>
4 HANDLER <em class="replaceable"><code>call_handler</code></em> [ INLINE <em class="replaceable"><code>inline_handler</code></em> ] [ VALIDATOR <em class="replaceable"><code>valfunction</code></em> ]
5 CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <em class="replaceable"><code>name</code></em>
6 </pre></div><div class="refsect1" id="SQL-CREATELANGUAGE-DESCRIPTION"><h2>Description</h2><p>
7 <code class="command">CREATE LANGUAGE</code> registers a new
8 procedural language with a <span class="productname">PostgreSQL</span>
9 database. Subsequently, functions and procedures can be
10 defined in this new language.
12 <code class="command">CREATE LANGUAGE</code> effectively associates the
13 language name with handler function(s) that are responsible for executing
14 functions written in the language. Refer to <a class="xref" href="plhandler.html" title="Chapter 57. Writing a Procedural Language Handler">Chapter 57</a>
15 for more information about language handlers.
17 <code class="command">CREATE OR REPLACE LANGUAGE</code> will either create a
18 new language, or replace an existing definition. If the language
19 already exists, its parameters are updated according to the command,
20 but the language's ownership and permissions settings do not change,
21 and any existing functions written in the language are assumed to still
25 <span class="productname">PostgreSQL</span> superuser privilege to
26 register a new language or change an existing language's parameters.
27 However, once the language is created it is valid to assign ownership of
28 it to a non-superuser, who may then drop it, change its permissions,
29 rename it, or assign it to a new owner. (Do not, however, assign
30 ownership of the underlying C functions to a non-superuser; that would
31 create a privilege escalation path for that user.)
33 The form of <code class="command">CREATE LANGUAGE</code> that does not supply
34 any handler function is obsolete. For backwards compatibility with
35 old dump files, it is interpreted as <code class="command">CREATE EXTENSION</code>.
36 That will work if the language has been packaged into an extension of
37 the same name, which is the conventional way to set up procedural
39 </p></div><div class="refsect1" id="SQL-CREATELANGUAGE-PARAMETERS"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">TRUSTED</code></span></dt><dd><p><code class="literal">TRUSTED</code> specifies that the language does
40 not grant access to data that the user would not otherwise
41 have. If this key word is omitted
42 when registering the language, only users with the
43 <span class="productname">PostgreSQL</span> superuser privilege can
44 use this language to create new functions.
45 </p></dd><dt><span class="term"><code class="literal">PROCEDURAL</code></span></dt><dd><p>
47 </p></dd><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
48 The name of the new procedural language.
49 The name must be unique among the languages in the database.
50 </p></dd><dt><span class="term"><code class="literal">HANDLER</code> <em class="replaceable"><code>call_handler</code></em></span></dt><dd><p><em class="replaceable"><code>call_handler</code></em> is
51 the name of a previously registered function that will be
52 called to execute the procedural language's functions. The call
53 handler for a procedural language must be written in a compiled
54 language such as C with version 1 call convention and
55 registered with <span class="productname">PostgreSQL</span> as a
56 function taking no arguments and returning the
57 <code class="type">language_handler</code> type, a placeholder type that is
58 simply used to identify the function as a call handler.
59 </p></dd><dt><span class="term"><code class="literal">INLINE</code> <em class="replaceable"><code>inline_handler</code></em></span></dt><dd><p><em class="replaceable"><code>inline_handler</code></em> is the
60 name of a previously registered function that will be called
61 to execute an anonymous code block
62 (<a class="link" href="sql-do.html" title="DO"><code class="command">DO</code></a> command)
64 If no <em class="replaceable"><code>inline_handler</code></em>
65 function is specified, the language does not support anonymous code
67 The handler function must take one argument of
68 type <code class="type">internal</code>, which will be the <code class="command">DO</code> command's
69 internal representation, and it will typically return
70 <code class="type">void</code>. The return value of the handler is ignored.
71 </p></dd><dt><span class="term"><code class="literal">VALIDATOR</code> <em class="replaceable"><code>valfunction</code></em></span></dt><dd><p><em class="replaceable"><code>valfunction</code></em> is the
72 name of a previously registered function that will be called
73 when a new function in the language is created, to validate the
76 validator function is specified, then a new function will not
77 be checked when it is created.
78 The validator function must take one argument of
79 type <code class="type">oid</code>, which will be the OID of the
80 to-be-created function, and will typically return <code class="type">void</code>.
82 A validator function would typically inspect the function body
83 for syntactical correctness, but it can also look at other
84 properties of the function, for example if the language cannot
85 handle certain argument types. To signal an error, the
86 validator function should use the <code class="function">ereport()</code>
87 function. The return value of the function is ignored.
88 </p></dd></dl></div></div><div class="refsect1" id="SQL-CREATELANGUAGE-NOTES"><h2>Notes</h2><p>
89 Use <a class="link" href="sql-droplanguage.html" title="DROP LANGUAGE"><code class="command">DROP LANGUAGE</code></a> to drop procedural languages.
91 The system catalog <code class="classname">pg_language</code> (see <a class="xref" href="catalog-pg-language.html" title="52.29. pg_language">Section 52.29</a>) records information about the
92 currently installed languages. Also, the <span class="application">psql</span>
93 command <code class="command">\dL</code> lists the installed languages.
95 To create functions in a procedural language, a user must have the
96 <code class="literal">USAGE</code> privilege for the language. By default,
97 <code class="literal">USAGE</code> is granted to <code class="literal">PUBLIC</code> (i.e., everyone)
98 for trusted languages. This can be revoked if desired.
100 Procedural languages are local to individual databases.
101 However, a language can be installed into the <code class="literal">template1</code>
102 database, which will cause it to be available automatically in
103 all subsequently-created databases.
104 </p></div><div class="refsect1" id="SQL-CREATELANGUAGE-EXAMPLES"><h2>Examples</h2><p>
105 A minimal sequence for creating a new procedural language is:
106 </p><pre class="programlisting">
107 CREATE FUNCTION plsample_call_handler() RETURNS language_handler
108 AS '$libdir/plsample'
110 CREATE LANGUAGE plsample
111 HANDLER plsample_call_handler;
113 Typically that would be written in an extension's creation script,
114 and users would do this to install the extension:
115 </p><pre class="programlisting">
116 CREATE EXTENSION plsample;
117 </pre></div><div class="refsect1" id="SQL-CREATELANGUAGE-COMPAT"><h2>Compatibility</h2><p>
118 <code class="command">CREATE LANGUAGE</code> is a
119 <span class="productname">PostgreSQL</span> extension.
120 </p></div><div class="refsect1" id="id-1.9.3.70.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-alterlanguage.html" title="ALTER LANGUAGE"><span class="refentrytitle">ALTER LANGUAGE</span></a>, <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a>, <a class="xref" href="sql-droplanguage.html" title="DROP LANGUAGE"><span class="refentrytitle">DROP LANGUAGE</span></a>, <a class="xref" href="sql-grant.html" title="GRANT"><span class="refentrytitle">GRANT</span></a>, <a class="xref" href="sql-revoke.html" title="REVOKE"><span class="refentrytitle">REVOKE</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createindex.html" title="CREATE INDEX">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-creatematerializedview.html" title="CREATE MATERIALIZED VIEW">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE INDEX </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE MATERIALIZED VIEW</td></tr></table></div></body></html>