gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
5.6KB

  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>9.10. Enum Support Functions</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="functions-datetime.html" title="9.9. Date/Time Functions and Operators" /><link rel="next" href="functions-geometry.html" title="9.11. Geometric Functions and Operators" /></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">9.10. Enum Support Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-datetime.html" title="9.9. Date/Time Functions and Operators">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</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="functions-geometry.html" title="9.11. Geometric Functions and Operators">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUNCTIONS-ENUM"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.10. Enum Support Functions</h2></div></div></div><p>
  3. For enum types (described in <a class="xref" href="datatype-enum.html" title="8.7. Enumerated Types">Section 8.7</a>),
  4. there are several functions that allow cleaner programming without
  5. hard-coding particular values of an enum type.
  6. These are listed in <a class="xref" href="functions-enum.html#FUNCTIONS-ENUM-TABLE" title="Table 9.33. Enum Support Functions">Table 9.33</a>. The examples
  7. assume an enum type created as:
  8. </p><pre class="programlisting">
  9. CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
  10. </pre><p>
  11. </p><div class="table" id="FUNCTIONS-ENUM-TABLE"><p class="title"><strong>Table 9.33. Enum Support Functions</strong></p><div class="table-contents"><table class="table" summary="Enum Support Functions" border="1"><colgroup><col /><col /><col /><col /></colgroup><thead><tr><th>Function</th><th>Description</th><th>Example</th><th>Example Result</th></tr></thead><tbody><tr><td>
  12. <a id="id-1.5.8.15.3.2.2.1.1.1" class="indexterm"></a>
  13. <code class="literal">enum_first(anyenum)</code>
  14. </td><td>Returns the first value of the input enum type</td><td><code class="literal">enum_first(null::rainbow)</code></td><td><code class="literal">red</code></td></tr><tr><td>
  15. <a id="id-1.5.8.15.3.2.2.2.1.1" class="indexterm"></a>
  16. <code class="literal">enum_last(anyenum)</code>
  17. </td><td>Returns the last value of the input enum type</td><td><code class="literal">enum_last(null::rainbow)</code></td><td><code class="literal">purple</code></td></tr><tr><td>
  18. <a id="id-1.5.8.15.3.2.2.3.1.1" class="indexterm"></a>
  19. <code class="literal">enum_range(anyenum)</code>
  20. </td><td>Returns all values of the input enum type in an ordered array</td><td><code class="literal">enum_range(null::rainbow)</code></td><td><code class="literal">{red,orange,yellow,green,blue,purple}</code></td></tr><tr><td rowspan="3"><code class="literal">enum_range(anyenum, anyenum)</code></td><td rowspan="3">
  21. Returns the range between the two given enum values, as an ordered
  22. array. The values must be from the same enum type. If the first
  23. parameter is null, the result will start with the first value of
  24. the enum type.
  25. If the second parameter is null, the result will end with the last
  26. value of the enum type.
  27. </td><td><code class="literal">enum_range('orange'::rainbow, 'green'::rainbow)</code></td><td><code class="literal">{orange,yellow,green}</code></td></tr><tr><td><code class="literal">enum_range(NULL, 'green'::rainbow)</code></td><td><code class="literal">{red,orange,yellow,green}</code></td></tr><tr><td><code class="literal">enum_range('orange'::rainbow, NULL)</code></td><td><code class="literal">{orange,yellow,green,blue,purple}</code></td></tr></tbody></table></div></div><br class="table-break" /><p>
  28. Notice that except for the two-argument form of <code class="function">enum_range</code>,
  29. these functions disregard the specific value passed to them; they care
  30. only about its declared data type. Either null or a specific value of
  31. the type can be passed, with the same result. It is more common to
  32. apply these functions to a table column or function argument than to
  33. a hardwired type name as suggested by the examples.
  34. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-datetime.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-geometry.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.9. Date/Time Functions and Operators </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 9.11. Geometric Functions and Operators</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1