summaryrefslogtreecommitdiff
path: root/doc/src/sgml/func/func-enum.sgml
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2025-08-04 08:56:48 -0400
committerAndrew Dunstan <andrew@dunslane.net>2025-08-04 09:04:56 -0400
commit4e23c9ef65accde7eb3e56aa28d50ae5cf79b64b (patch)
treee56f52b0d1b8409794a5ac0cc54ee7a322c58c6a /doc/src/sgml/func/func-enum.sgml
parent6ae268cf284c5a706455e164f8879bd721296535 (diff)
Split func.sgml into more manageable pieces
func.sgml has grown over the years to the point where it is very difficult to manage. This commit splits out each sect1 piece into its own file, which is then included in the main file, so that the built documentation should be identical to the pre-split documentation. All these new files are placed in a new "func" subdirectory, and the previous func.sgml is removed. Done using scripts developed by: Author: jian he <jian.universality@gmail.com> Discussion: https://postgr.es/m/CACJufxFgAh1--EMwOjMuANe=VTmjkNaZjH+AzSe04-8ZCGiESA@mail.gmail.com
Diffstat (limited to 'doc/src/sgml/func/func-enum.sgml')
-rw-r--r--doc/src/sgml/func/func-enum.sgml121
1 files changed, 121 insertions, 0 deletions
diff --git a/doc/src/sgml/func/func-enum.sgml b/doc/src/sgml/func/func-enum.sgml
new file mode 100644
index 00000000000..6227afe4057
--- /dev/null
+++ b/doc/src/sgml/func/func-enum.sgml
@@ -0,0 +1,121 @@
+ <sect1 id="functions-enum">
+ <title>Enum Support Functions</title>
+
+ <para>
+ For enum types (described in <xref linkend="datatype-enum"/>),
+ there are several functions that allow cleaner programming without
+ hard-coding particular values of an enum type.
+ These are listed in <xref linkend="functions-enum-table"/>. The examples
+ assume an enum type created as:
+
+<programlisting>
+CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
+</programlisting>
+
+ </para>
+
+ <table id="functions-enum-table">
+ <title>Enum Support Functions</title>
+ <tgroup cols="1">
+ <thead>
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ Function
+ </para>
+ <para>
+ Description
+ </para>
+ <para>
+ Example(s)
+ </para></entry>
+ </row>
+ </thead>
+
+ <tbody>
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ <indexterm>
+ <primary>enum_first</primary>
+ </indexterm>
+ <function>enum_first</function> ( <type>anyenum</type> )
+ <returnvalue>anyenum</returnvalue>
+ </para>
+ <para>
+ Returns the first value of the input enum type.
+ </para>
+ <para>
+ <literal>enum_first(null::rainbow)</literal>
+ <returnvalue>red</returnvalue>
+ </para></entry>
+ </row>
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ <indexterm>
+ <primary>enum_last</primary>
+ </indexterm>
+ <function>enum_last</function> ( <type>anyenum</type> )
+ <returnvalue>anyenum</returnvalue>
+ </para>
+ <para>
+ Returns the last value of the input enum type.
+ </para>
+ <para>
+ <literal>enum_last(null::rainbow)</literal>
+ <returnvalue>purple</returnvalue>
+ </para></entry>
+ </row>
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ <indexterm>
+ <primary>enum_range</primary>
+ </indexterm>
+ <function>enum_range</function> ( <type>anyenum</type> )
+ <returnvalue>anyarray</returnvalue>
+ </para>
+ <para>
+ Returns all values of the input enum type in an ordered array.
+ </para>
+ <para>
+ <literal>enum_range(null::rainbow)</literal>
+ <returnvalue>{red,orange,yellow,&zwsp;green,blue,purple}</returnvalue>
+ </para></entry>
+ </row>
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ <function>enum_range</function> ( <type>anyenum</type>, <type>anyenum</type> )
+ <returnvalue>anyarray</returnvalue>
+ </para>
+ <para>
+ 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.
+ </para>
+ <para>
+ <literal>enum_range('orange'::rainbow, 'green'::rainbow)</literal>
+ <returnvalue>{orange,yellow,green}</returnvalue>
+ </para>
+ <para>
+ <literal>enum_range(NULL, 'green'::rainbow)</literal>
+ <returnvalue>{red,orange,&zwsp;yellow,green}</returnvalue>
+ </para>
+ <para>
+ <literal>enum_range('orange'::rainbow, NULL)</literal>
+ <returnvalue>{orange,yellow,green,&zwsp;blue,purple}</returnvalue>
+ </para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <para>
+ Notice that except for the two-argument form of <function>enum_range</function>,
+ 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.
+ </para>
+ </sect1>