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 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 18.0 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 <a href="#FUNCTIONS-ENUM" class="id_link">#</a></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.35. Enum Support Functions">Table 9.35</a>. The examples
7 assume an enum type created as:
9 </p><pre class="programlisting">
10 CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
13 </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">
21 </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
22 <a id="id-1.5.8.16.3.2.2.1.1.1.1" class="indexterm"></a>
23 <code class="function">enum_first</code> ( <code class="type">anyenum</code> )
24 → <code class="returnvalue">anyenum</code>
27 Returns the first value of the input enum type.
30 <code class="literal">enum_first(null::rainbow)</code>
31 → <code class="returnvalue">red</code>
32 </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
33 <a id="id-1.5.8.16.3.2.2.2.1.1.1" class="indexterm"></a>
34 <code class="function">enum_last</code> ( <code class="type">anyenum</code> )
35 → <code class="returnvalue">anyenum</code>
38 Returns the last value of the input enum type.
41 <code class="literal">enum_last(null::rainbow)</code>
42 → <code class="returnvalue">purple</code>
43 </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
44 <a id="id-1.5.8.16.3.2.2.3.1.1.1" class="indexterm"></a>
45 <code class="function">enum_range</code> ( <code class="type">anyenum</code> )
46 → <code class="returnvalue">anyarray</code>
49 Returns all values of the input enum type in an ordered array.
52 <code class="literal">enum_range(null::rainbow)</code>
53 → <code class="returnvalue">{red,orange,yellow,green,blue,purple}</code>
54 </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
55 <code class="function">enum_range</code> ( <code class="type">anyenum</code>, <code class="type">anyenum</code> )
56 → <code class="returnvalue">anyarray</code>
59 Returns the range between the two given enum values, as an ordered
60 array. The values must be from the same enum type. If the first
61 parameter is null, the result will start with the first value of
63 If the second parameter is null, the result will end with the last
64 value of the enum type.
67 <code class="literal">enum_range('orange'::rainbow, 'green'::rainbow)</code>
68 → <code class="returnvalue">{orange,yellow,green}</code>
71 <code class="literal">enum_range(NULL, 'green'::rainbow)</code>
72 → <code class="returnvalue">{red,orange,yellow,green}</code>
75 <code class="literal">enum_range('orange'::rainbow, NULL)</code>
76 → <code class="returnvalue">{orange,yellow,green,blue,purple}</code>
77 </p></td></tr></tbody></table></div></div><br class="table-break" /><p>
78 Notice that except for the two-argument form of <code class="function">enum_range</code>,
79 these functions disregard the specific value passed to them; they care
80 only about its declared data type. Either null or a specific value of
81 the type can be passed, with the same result. It is more common to
82 apply these functions to a table column or function argument than to
83 a hardwired type name as used in the examples.
84 </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 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 9.11. Geometric Functions and Operators</td></tr></table></div></body></html>