|
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <!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>
- For enum types (described in <a class="xref" href="datatype-enum.html" title="8.7. Enumerated Types">Section 8.7</a>),
- there are several functions that allow cleaner programming without
- hard-coding particular values of an enum type.
- 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
- assume an enum type created as:
-
- </p><pre class="programlisting">
- CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
- </pre><p>
-
- </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>
- <a id="id-1.5.8.15.3.2.2.1.1.1" class="indexterm"></a>
- <code class="literal">enum_first(anyenum)</code>
- </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>
- <a id="id-1.5.8.15.3.2.2.2.1.1" class="indexterm"></a>
- <code class="literal">enum_last(anyenum)</code>
- </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>
- <a id="id-1.5.8.15.3.2.2.3.1.1" class="indexterm"></a>
- <code class="literal">enum_range(anyenum)</code>
- </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">
- Returns the range between the two given enum values, as an ordered
- array. The values must be from the same enum type. If the first
- parameter is null, the result will start with the first value of
- the enum type.
- If the second parameter is null, the result will end with the last
- value of the enum type.
- </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>
- Notice that except for the two-argument form of <code class="function">enum_range</code>,
- these functions disregard the specific value passed to them; they care
- only about its declared data type. Either null or a specific value of
- the type can be passed, with the same result. It is more common to
- apply these functions to a table column or function argument than to
- a hardwired type name as suggested by the examples.
- </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>
|