codekingpro/portable-devtools
115k
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 16.3 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">3CREATE [ 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> ]5CREATE [ 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 new8 procedural language with a <span class="productname">PostgreSQL</span>9 database. Subsequently, functions and procedures can be10 defined in this new language.11 </p><p>12 <code class="command">CREATE LANGUAGE</code> effectively associates the13 language name with handler function(s) that are responsible for executing14 functions written in the language. Refer to <a class="xref" href="plhandler.html" title="Chapter 58. Writing a Procedural Language Handler">Chapter 58</a>15 for more information about language handlers.16 </p><p>17 <code class="command">CREATE OR REPLACE LANGUAGE</code> will either create a18 new language, or replace an existing definition. If the language19 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 still22 be valid.23 </p><p>24 One must have the25 <span class="productname">PostgreSQL</span> superuser privilege to26 register a new language or change an existing language's parameters.27 However, once the language is created it is valid to assign ownership of28 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, assign30 ownership of the underlying C functions to a non-superuser; that would31 create a privilege escalation path for that user.)32 </p><p>33 The form of <code class="command">CREATE LANGUAGE</code> that does not supply34 any handler function is obsolete. For backwards compatibility with35 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 of37 the same name, which is the conventional way to set up procedural38 languages.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 does40 not grant access to data that the user would not otherwise41 have. If this key word is omitted42 when registering the language, only users with the43 <span class="productname">PostgreSQL</span> superuser privilege can44 use this language to create new functions.45 </p></dd><dt><span class="term"><code class="literal">PROCEDURAL</code></span></dt><dd><p>46 This is a noise word.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> is51 the name of a previously registered function that will be52 called to execute the procedural language's functions. The call53 handler for a procedural language must be written in a compiled54 language such as C with version 1 call convention and55 registered with <span class="productname">PostgreSQL</span> as a56 function taking no arguments and returning the57 <code class="type">language_handler</code> type, a placeholder type that is58 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 the60 name of a previously registered function that will be called61 to execute an anonymous code block62 (<a class="link" href="sql-do.html" title="DO"><code class="command">DO</code></a> command)63 in this language.64 If no <em class="replaceable"><code>inline_handler</code></em>65 function is specified, the language does not support anonymous code66 blocks.67 The handler function must take one argument of68 type <code class="type">internal</code>, which will be the <code class="command">DO</code> command's69 internal representation, and it will typically return70 <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 the72 name of a previously registered function that will be called73 when a new function in the language is created, to validate the74 new function.75 If no76 validator function is specified, then a new function will not77 be checked when it is created.78 The validator function must take one argument of79 type <code class="type">oid</code>, which will be the OID of the80 to-be-created function, and will typically return <code class="type">void</code>.81 </p><p>82 A validator function would typically inspect the function body83 for syntactical correctness, but it can also look at other84 properties of the function, for example if the language cannot85 handle certain argument types. To signal an error, the86 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.90 </p><p>91 The system catalog <code class="classname">pg_language</code> (see <a class="xref" href="catalog-pg-language.html" title="53.29. pg_language">Section 53.29</a>) records information about the92 currently installed languages. Also, the <span class="application">psql</span>93 command <code class="command">\dL</code> lists the installed languages.94 </p><p>95 To create functions in a procedural language, a user must have the96 <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.99 </p><p>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 in103 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">107CREATE FUNCTION plsample_call_handler() RETURNS language_handler108 AS '$libdir/plsample'109 LANGUAGE C;110CREATE LANGUAGE plsample111 HANDLER plsample_call_handler;112</pre><p>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">116CREATE EXTENSION plsample;117</pre></div><div class="refsect1" id="SQL-CREATELANGUAGE-COMPAT"><h2>Compatibility</h2><p>118 <code class="command">CREATE LANGUAGE</code> is a119 <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 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE MATERIALIZED VIEW</td></tr></table></div></body></html>