summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/html/functions-enum.html
blob: 7f4e1346089688c2bcbdb28a512b9676302a567c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?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 Vsnapshot" /><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 id="docContent" class="container-fluid col-10"><div 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 15.6 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 /></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.35. Enum Support Functions">Table 9.35</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.35. Enum Support Functions</strong></p><div class="table-contents"><table class="table" summary="Enum Support Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
        Function
       </p>
       <p>
        Description
       </p>
       <p>
        Example(s)
       </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.16.3.2.2.1.1.1.1" class="indexterm"></a>
        <code class="function">enum_first</code> ( <code class="type">anyenum</code> )
        → <code class="returnvalue">anyenum</code>
       </p>
       <p>
        Returns the first value of the input enum type.
       </p>
       <p>
        <code class="literal">enum_first(null::rainbow)</code><code class="returnvalue">red</code>
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.16.3.2.2.2.1.1.1" class="indexterm"></a>
        <code class="function">enum_last</code> ( <code class="type">anyenum</code> )
        → <code class="returnvalue">anyenum</code>
       </p>
       <p>
        Returns the last value of the input enum type.
       </p>
       <p>
        <code class="literal">enum_last(null::rainbow)</code><code class="returnvalue">purple</code>
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <a id="id-1.5.8.16.3.2.2.3.1.1.1" class="indexterm"></a>
        <code class="function">enum_range</code> ( <code class="type">anyenum</code> )
        → <code class="returnvalue">anyarray</code>
       </p>
       <p>
        Returns all values of the input enum type in an ordered array.
       </p>
       <p>
        <code class="literal">enum_range(null::rainbow)</code><code class="returnvalue">{red,orange,yellow,​green,blue,purple}</code>
       </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
        <code class="function">enum_range</code> ( <code class="type">anyenum</code>, <code class="type">anyenum</code> )
        → <code class="returnvalue">anyarray</code>
       </p>
       <p>
        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.
       </p>
       <p>
        <code class="literal">enum_range('orange'::rainbow, 'green'::rainbow)</code><code class="returnvalue">{orange,yellow,green}</code>
       </p>
       <p>
        <code class="literal">enum_range(NULL, 'green'::rainbow)</code><code class="returnvalue">{red,orange,​yellow,green}</code>
       </p>
       <p>
        <code class="literal">enum_range('orange'::rainbow, NULL)</code><code class="returnvalue">{orange,yellow,green,​blue,purple}</code>
       </p></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 used in 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" title="9.9. Date/Time Functions and Operators">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-geometry.html" title="9.11. Geometric Functions and Operators">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" title="PostgreSQL 15.6 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 9.11. Geometric Functions and Operators</td></tr></table></div></body></html>