gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

177 linhas
15KB

  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 V1.79.1" /><link rel="prev" href="sql-createindex.html" title="CREATE INDEX" /><link rel="next" href="sql-creatematerializedview.html" title="CREATE MATERIALIZED VIEW" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" 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 12.4 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></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 ] [ PROCEDURAL ] LANGUAGE <em class="replaceable"><code>name</code></em>
  4. CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <em class="replaceable"><code>name</code></em>
  5. 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> ]
  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.
  11. </p><div class="note"><h3 class="title">Note</h3><p>
  12. As of <span class="productname">PostgreSQL</span> 9.1, most procedural
  13. languages have been made into <span class="quote">“<span class="quote">extensions</span>”</span>, and should
  14. therefore be installed with <a class="xref" href="sql-createextension.html" title="CREATE EXTENSION"><span class="refentrytitle">CREATE EXTENSION</span></a>
  15. not <code class="command">CREATE LANGUAGE</code>. Direct use of
  16. <code class="command">CREATE LANGUAGE</code> should now be confined to
  17. extension installation scripts. If you have a <span class="quote">“<span class="quote">bare</span>”</span>
  18. language in your database, perhaps as a result of an upgrade,
  19. you can convert it to an extension using
  20. <code class="literal">CREATE EXTENSION <em class="replaceable"><code>langname</code></em> FROM
  21. unpackaged</code>.
  22. </p></div><p>
  23. <code class="command">CREATE LANGUAGE</code> effectively associates the
  24. language name with handler function(s) that are responsible for executing
  25. functions written in the language. Refer to <a class="xref" href="plhandler.html" title="Chapter 55. Writing a Procedural Language Handler">Chapter 55</a>
  26. for more information about language handlers.
  27. </p><p>
  28. There are two forms of the <code class="command">CREATE LANGUAGE</code> command.
  29. In the first form, the user supplies just the name of the desired
  30. language, and the <span class="productname">PostgreSQL</span> server consults
  31. the <a class="link" href="catalog-pg-pltemplate.html" title="51.37. pg_pltemplate"><code class="structname">pg_pltemplate</code></a>
  32. system catalog to determine the correct parameters. In the second form,
  33. the user supplies the language parameters along with the language name.
  34. The second form can be used to create a language that is not defined in
  35. <code class="structname">pg_pltemplate</code>, but this approach is considered obsolescent.
  36. </p><p>
  37. When the server finds an entry in the <code class="structname">pg_pltemplate</code> catalog
  38. for the given language name, it will use the catalog data even if the
  39. command includes language parameters. This behavior simplifies loading of
  40. old dump files, which are likely to contain out-of-date information
  41. about language support functions.
  42. </p><p>
  43. Ordinarily, the user must have the
  44. <span class="productname">PostgreSQL</span> superuser privilege to
  45. register a new language. However, the owner of a database can register
  46. a new language within that database if the language is listed in
  47. the <code class="structname">pg_pltemplate</code> catalog and is marked
  48. as allowed to be created by database owners (<code class="structfield">tmpldbacreate</code>
  49. is true). The default is that trusted languages can be created
  50. by database owners, but this can be adjusted by superusers by modifying
  51. the contents of <code class="structname">pg_pltemplate</code>.
  52. The creator of a language becomes its owner and can later
  53. drop it, rename it, or assign it to a new owner.
  54. </p><p>
  55. <code class="command">CREATE OR REPLACE LANGUAGE</code> will either create a
  56. new language, or replace an existing definition. If the language
  57. already exists, its parameters are updated according to the values
  58. specified or taken from <code class="structname">pg_pltemplate</code>,
  59. but the language's ownership and permissions settings do not change,
  60. and any existing functions written in the language are assumed to still
  61. be valid. In addition to the normal privilege requirements for creating
  62. a language, the user must be superuser or owner of the existing language.
  63. The <code class="literal">REPLACE</code> case is mainly meant to be used to
  64. ensure that the language exists. If the language has a
  65. <code class="structname">pg_pltemplate</code> entry then <code class="literal">REPLACE</code>
  66. will not actually change anything about an existing definition, except in
  67. the unusual case where the <code class="structname">pg_pltemplate</code> entry
  68. has been modified since the language was created.
  69. </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
  70. not grant access to data that the user would not otherwise
  71. have. If this key word is omitted
  72. when registering the language, only users with the
  73. <span class="productname">PostgreSQL</span> superuser privilege can
  74. use this language to create new functions.
  75. </p></dd><dt><span class="term"><code class="literal">PROCEDURAL</code></span></dt><dd><p>
  76. This is a noise word.
  77. </p></dd><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
  78. The name of the new procedural language.
  79. The name must be unique among the languages in the database.
  80. </p><p>
  81. For backward compatibility, the name can be enclosed by single
  82. quotes.
  83. </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
  84. the name of a previously registered function that will be
  85. called to execute the procedural language's functions. The call
  86. handler for a procedural language must be written in a compiled
  87. language such as C with version 1 call convention and
  88. registered with <span class="productname">PostgreSQL</span> as a
  89. function taking no arguments and returning the
  90. <code class="type">language_handler</code> type, a placeholder type that is
  91. simply used to identify the function as a call handler.
  92. </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
  93. name of a previously registered function that will be called
  94. to execute an anonymous code block
  95. (<a class="xref" href="sql-do.html" title="DO"><span class="refentrytitle">DO</span></a> command)
  96. in this language.
  97. If no <em class="replaceable"><code>inline_handler</code></em>
  98. function is specified, the language does not support anonymous code
  99. blocks.
  100. The handler function must take one argument of
  101. type <code class="type">internal</code>, which will be the <code class="command">DO</code> command's
  102. internal representation, and it will typically return
  103. <code class="type">void</code>. The return value of the handler is ignored.
  104. </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
  105. name of a previously registered function that will be called
  106. when a new function in the language is created, to validate the
  107. new function.
  108. If no
  109. validator function is specified, then a new function will not
  110. be checked when it is created.
  111. The validator function must take one argument of
  112. type <code class="type">oid</code>, which will be the OID of the
  113. to-be-created function, and will typically return <code class="type">void</code>.
  114. </p><p>
  115. A validator function would typically inspect the function body
  116. for syntactical correctness, but it can also look at other
  117. properties of the function, for example if the language cannot
  118. handle certain argument types. To signal an error, the
  119. validator function should use the <code class="function">ereport()</code>
  120. function. The return value of the function is ignored.
  121. </p></dd></dl></div><p>
  122. The <code class="literal">TRUSTED</code> option and the support function name(s) are
  123. ignored if the server has an entry for the specified language
  124. name in <code class="structname">pg_pltemplate</code>.
  125. </p></div><div class="refsect1" id="SQL-CREATELANGUAGE-NOTES"><h2>Notes</h2><p>
  126. Use <a class="xref" href="sql-droplanguage.html" title="DROP LANGUAGE"><span class="refentrytitle">DROP LANGUAGE</span></a> to drop procedural languages.
  127. </p><p>
  128. The system catalog <code class="classname">pg_language</code> (see <a class="xref" href="catalog-pg-language.html" title="51.29. pg_language">Section 51.29</a>) records information about the
  129. currently installed languages. Also, the <span class="application">psql</span>
  130. command <code class="command">\dL</code> lists the installed languages.
  131. </p><p>
  132. To create functions in a procedural language, a user must have the
  133. <code class="literal">USAGE</code> privilege for the language. By default,
  134. <code class="literal">USAGE</code> is granted to <code class="literal">PUBLIC</code> (i.e., everyone)
  135. for trusted languages. This can be revoked if desired.
  136. </p><p>
  137. Procedural languages are local to individual databases.
  138. However, a language can be installed into the <code class="literal">template1</code>
  139. database, which will cause it to be available automatically in
  140. all subsequently-created databases.
  141. </p><p>
  142. The call handler function, the inline handler function (if any),
  143. and the validator function (if any)
  144. must already exist if the server does not have an entry for the language
  145. in <code class="structname">pg_pltemplate</code>. But when there is an entry,
  146. the functions need not already exist;
  147. they will be automatically defined if not present in the database.
  148. (This might result in <code class="command">CREATE LANGUAGE</code> failing, if the
  149. shared library that implements the language is not available in
  150. the installation.)
  151. </p><p>
  152. In <span class="productname">PostgreSQL</span> versions before 7.3, it was
  153. necessary to declare handler functions as returning the placeholder
  154. type <code class="type">opaque</code>, rather than <code class="type">language_handler</code>.
  155. To support loading
  156. of old dump files, <code class="command">CREATE LANGUAGE</code> will accept a function
  157. declared as returning <code class="type">opaque</code>, but it will issue a notice and
  158. change the function's declared return type to <code class="type">language_handler</code>.
  159. </p></div><div class="refsect1" id="SQL-CREATELANGUAGE-EXAMPLES"><h2>Examples</h2><p>
  160. The preferred way of creating any of the standard procedural languages
  161. is just:
  162. </p><pre class="programlisting">
  163. CREATE LANGUAGE plperl;
  164. </pre><p>
  165. </p><p>
  166. For a language not known in the <code class="structname">pg_pltemplate</code> catalog, a
  167. sequence such as this is needed:
  168. </p><pre class="programlisting">
  169. CREATE FUNCTION plsample_call_handler() RETURNS language_handler
  170. AS '$libdir/plsample'
  171. LANGUAGE C;
  172. CREATE LANGUAGE plsample
  173. HANDLER plsample_call_handler;
  174. </pre></div><div class="refsect1" id="SQL-CREATELANGUAGE-COMPAT"><h2>Compatibility</h2><p>
  175. <code class="command">CREATE LANGUAGE</code> is a
  176. <span class="productname">PostgreSQL</span> extension.
  177. </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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-creatematerializedview.html">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">Home</a></td><td width="40%" align="right" valign="top"> CREATE MATERIALIZED VIEW</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1