]> begriffs open source - ai-pg/blob - full-docs/txt/functions-enum.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / functions-enum.txt
1
2 9.10. Enum Support Functions #
3
4    For enum types (described in Section 8.7), there are several functions
5    that allow cleaner programming without hard-coding particular values of
6    an enum type. These are listed in Table 9.35. The examples assume an
7    enum type created as:
8 CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
9 ');
10
11    Table 9.35. Enum Support Functions
12
13    Function
14
15    Description
16
17    Example(s)
18
19    enum_first ( anyenum ) → anyenum
20
21    Returns the first value of the input enum type.
22
23    enum_first(null::rainbow) → red
24
25    enum_last ( anyenum ) → anyenum
26
27    Returns the last value of the input enum type.
28
29    enum_last(null::rainbow) → purple
30
31    enum_range ( anyenum ) → anyarray
32
33    Returns all values of the input enum type in an ordered array.
34
35    enum_range(null::rainbow) → {red,orange,yellow,​green,blue,purple}
36
37    enum_range ( anyenum, anyenum ) → anyarray
38
39    Returns the range between the two given enum values, as an ordered
40    array. The values must be from the same enum type. If the first
41    parameter is null, the result will start with the first value of the
42    enum type. If the second parameter is null, the result will end with
43    the last value of the enum type.
44
45    enum_range('orange'::rainbow, 'green'::rainbow) → {orange,yellow,green}
46
47    enum_range(NULL, 'green'::rainbow) → {red,orange,​yellow,green}
48
49    enum_range('orange'::rainbow, NULL) →
50    {orange,yellow,green,​blue,purple}
51
52    Notice that except for the two-argument form of enum_range, these
53    functions disregard the specific value passed to them; they care only
54    about its declared data type. Either null or a specific value of the
55    type can be passed, with the same result. It is more common to apply
56    these functions to a table column or function argument than to a
57    hardwired type name as used in the examples.