2 9.10. Enum Support Functions #
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
8 CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
11 Table 9.35. Enum Support Functions
19 enum_first ( anyenum ) → anyenum
21 Returns the first value of the input enum type.
23 enum_first(null::rainbow) → red
25 enum_last ( anyenum ) → anyenum
27 Returns the last value of the input enum type.
29 enum_last(null::rainbow) → purple
31 enum_range ( anyenum ) → anyarray
33 Returns all values of the input enum type in an ordered array.
35 enum_range(null::rainbow) → {red,orange,yellow,green,blue,purple}
37 enum_range ( anyenum, anyenum ) → anyarray
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.
45 enum_range('orange'::rainbow, 'green'::rainbow) → {orange,yellow,green}
47 enum_range(NULL, 'green'::rainbow) → {red,orange,yellow,green}
49 enum_range('orange'::rainbow, NULL) →
50 {orange,yellow,green,blue,purple}
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.