gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

105 lines
9.9KB

  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>42.1. Overview</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="plpgsql.html" title="Chapter 42. PL/pgSQL - SQL Procedural Language" /><link rel="next" href="plpgsql-structure.html" title="42.2. Structure of PL/pgSQL" /></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">42.1. Overview</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="plpgsql.html" title="Chapter 42. PL/pgSQL - SQL Procedural Language">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="plpgsql.html" title="Chapter 42. PL/pgSQL - SQL Procedural Language">Up</a></td><th width="60%" align="center">Chapter 42. <span xmlns="http://www.w3.org/1999/xhtml" class="application">PL/pgSQL</span> - <acronym xmlns="http://www.w3.org/1999/xhtml" class="acronym">SQL</acronym> Procedural Language</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="plpgsql-structure.html" title="42.2. Structure of PL/pgSQL">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="PLPGSQL-OVERVIEW"><div class="titlepage"><div><div><h2 class="title" style="clear: both">42.1. Overview</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="plpgsql-overview.html#PLPGSQL-ADVANTAGES">42.1.1. Advantages of Using <span class="application">PL/pgSQL</span></a></span></dt><dt><span class="sect2"><a href="plpgsql-overview.html#PLPGSQL-ARGS-RESULTS">42.1.2. Supported Argument and Result Data Types</a></span></dt></dl></div><p>
  3. <span class="application">PL/pgSQL</span> is a loadable procedural
  4. language for the <span class="productname">PostgreSQL</span> database
  5. system. The design goals of <span class="application">PL/pgSQL</span> were to create
  6. a loadable procedural language that
  7. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  8. can be used to create functions and triggers,
  9. </p></li><li class="listitem"><p>
  10. adds control structures to the <acronym class="acronym">SQL</acronym> language,
  11. </p></li><li class="listitem"><p>
  12. can perform complex computations,
  13. </p></li><li class="listitem"><p>
  14. inherits all user-defined types, functions, and operators,
  15. </p></li><li class="listitem"><p>
  16. can be defined to be trusted by the server,
  17. </p></li><li class="listitem"><p>
  18. is easy to use.
  19. </p></li></ul></div><p>
  20. </p><p>
  21. Functions created with <span class="application">PL/pgSQL</span> can be
  22. used anywhere that built-in functions could be used.
  23. For example, it is possible to
  24. create complex conditional computation functions and later use
  25. them to define operators or use them in index expressions.
  26. </p><p>
  27. In <span class="productname">PostgreSQL</span> 9.0 and later,
  28. <span class="application">PL/pgSQL</span> is installed by default.
  29. However it is still a loadable module, so especially security-conscious
  30. administrators could choose to remove it.
  31. </p><div class="sect2" id="PLPGSQL-ADVANTAGES"><div class="titlepage"><div><div><h3 class="title">42.1.1. Advantages of Using <span class="application">PL/pgSQL</span></h3></div></div></div><p>
  32. <acronym class="acronym">SQL</acronym> is the language <span class="productname">PostgreSQL</span>
  33. and most other relational databases use as query language. It's
  34. portable and easy to learn. But every <acronym class="acronym">SQL</acronym>
  35. statement must be executed individually by the database server.
  36. </p><p>
  37. That means that your client application must send each query to
  38. the database server, wait for it to be processed, receive and
  39. process the results, do some computation, then send further
  40. queries to the server. All this incurs interprocess
  41. communication and will also incur network overhead if your client
  42. is on a different machine than the database server.
  43. </p><p>
  44. With <span class="application">PL/pgSQL</span> you can group a block of
  45. computation and a series of queries <span class="emphasis"><em>inside</em></span>
  46. the database server, thus having the power of a procedural
  47. language and the ease of use of SQL, but with considerable
  48. savings of client/server communication overhead.
  49. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p> Extra round trips between
  50. client and server are eliminated </p></li><li class="listitem"><p> Intermediate results that the client does not
  51. need do not have to be marshaled or transferred between server
  52. and client </p></li><li class="listitem"><p> Multiple rounds of query
  53. parsing can be avoided </p></li></ul></div><p> This can result in a considerable performance increase as
  54. compared to an application that does not use stored functions.
  55. </p><p>
  56. Also, with <span class="application">PL/pgSQL</span> you can use all
  57. the data types, operators and functions of SQL.
  58. </p></div><div class="sect2" id="PLPGSQL-ARGS-RESULTS"><div class="titlepage"><div><div><h3 class="title">42.1.2. Supported Argument and Result Data Types</h3></div></div></div><p>
  59. Functions written in <span class="application">PL/pgSQL</span> can accept
  60. as arguments any scalar or array data type supported by the server,
  61. and they can return a result of any of these types. They can also
  62. accept or return any composite type (row type) specified by name.
  63. It is also possible to declare a <span class="application">PL/pgSQL</span>
  64. function as accepting <code class="type">record</code>, which means that any
  65. composite type will do as input, or
  66. as returning <code class="type">record</code>, which means that the result
  67. is a row type whose columns are determined by specification in the
  68. calling query, as discussed in <a class="xref" href="queries-table-expressions.html#QUERIES-TABLEFUNCTIONS" title="7.2.1.4. Table Functions">Section 7.2.1.4</a>.
  69. </p><p>
  70. <span class="application">PL/pgSQL</span> functions can be declared to accept a variable
  71. number of arguments by using the <code class="literal">VARIADIC</code> marker. This
  72. works exactly the same way as for SQL functions, as discussed in
  73. <a class="xref" href="xfunc-sql.html#XFUNC-SQL-VARIADIC-FUNCTIONS" title="37.5.5. SQL Functions with Variable Numbers of Arguments">Section 37.5.5</a>.
  74. </p><p>
  75. <span class="application">PL/pgSQL</span> functions can also be declared to accept
  76. and return the polymorphic types
  77. <code class="type">anyelement</code>, <code class="type">anyarray</code>, <code class="type">anynonarray</code>,
  78. <code class="type">anyenum</code>, and <code class="type">anyrange</code>. The actual
  79. data types handled by a polymorphic function can vary from call to
  80. call, as discussed in <a class="xref" href="extend-type-system.html#EXTEND-TYPES-POLYMORPHIC" title="37.2.5. Polymorphic Types">Section 37.2.5</a>.
  81. An example is shown in <a class="xref" href="plpgsql-declarations.html#PLPGSQL-DECLARATION-PARAMETERS" title="42.3.1. Declaring Function Parameters">Section 42.3.1</a>.
  82. </p><p>
  83. <span class="application">PL/pgSQL</span> functions can also be declared to return
  84. a <span class="quote">“<span class="quote">set</span>”</span> (or table) of any data type that can be returned as
  85. a single instance. Such a function generates its output by executing
  86. <code class="command">RETURN NEXT</code> for each desired element of the result
  87. set, or by using <code class="command">RETURN QUERY</code> to output the result of
  88. evaluating a query.
  89. </p><p>
  90. Finally, a <span class="application">PL/pgSQL</span> function can be declared to return
  91. <code class="type">void</code> if it has no useful return value. (Alternatively, it
  92. could be written as a procedure in that case.)
  93. </p><p>
  94. <span class="application">PL/pgSQL</span> functions can also be declared with output
  95. parameters in place of an explicit specification of the return type.
  96. This does not add any fundamental capability to the language, but
  97. it is often convenient, especially for returning multiple values.
  98. The <code class="literal">RETURNS TABLE</code> notation can also be used in place
  99. of <code class="literal">RETURNS SETOF</code>.
  100. </p><p>
  101. Specific examples appear in
  102. <a class="xref" href="plpgsql-declarations.html#PLPGSQL-DECLARATION-PARAMETERS" title="42.3.1. Declaring Function Parameters">Section 42.3.1</a> and
  103. <a class="xref" href="plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING" title="42.6.1. Returning From a Function">Section 42.6.1</a>.
  104. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="plpgsql.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="plpgsql.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="plpgsql-structure.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 42. <span class="application">PL/pgSQL</span> - <acronym class="acronym">SQL</acronym> Procedural Language </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 42.2. Structure of <span class="application">PL/pgSQL</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1