1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.250.2.4 2010/07/29 19:34:36 petere Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.250.2.5 2010/08/10 20:41:28 petere Exp $ -->
2
2
3
3
<chapter id="datatype">
4
4
<title>Data Types</title>
@@ -2869,10 +2869,6 @@ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
2869
2869
2870
2870
Once created, the enum type can be used in table and function
2871
2871
definitions much like any other type:
2872
- </para>
2873
-
2874
- <example>
2875
- <title>Basic Enum Usage</title>
2876
2872
<programlisting>
2877
2873
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
2878
2874
CREATE TABLE person (
@@ -2886,7 +2882,7 @@ SELECT * FROM person WHERE current_mood = 'happy';
2886
2882
Moe | happy
2887
2883
(1 row)
2888
2884
</programlisting>
2889
- </example >
2885
+ </para >
2890
2886
</sect2>
2891
2887
2892
2888
<sect2>
@@ -2897,10 +2893,7 @@ SELECT * FROM person WHERE current_mood = 'happy';
2897
2893
order in which the values were listed when the type was created.
2898
2894
All standard comparison operators and related
2899
2895
aggregate functions are supported for enums. For example:
2900
- </para>
2901
-
2902
- <example>
2903
- <title>Enum Ordering</title>
2896
+
2904
2897
<programlisting>
2905
2898
INSERT INTO person VALUES ('Larry', 'sad');
2906
2899
INSERT INTO person VALUES ('Curly', 'ok');
@@ -2926,19 +2919,16 @@ WHERE current_mood = (SELECT MIN(current_mood) FROM person);
2926
2919
Larry
2927
2920
(1 row)
2928
2921
</programlisting>
2929
- </example >
2922
+ </para >
2930
2923
</sect2>
2931
2924
2932
2925
<sect2>
2933
2926
<title>Type Safety</title>
2934
2927
2935
2928
<para>
2936
2929
Each enumerated data type is separate and cannot
2937
- be compared with other enumerated types.
2938
- </para>
2930
+ be compared with other enumerated types. See this example:
2939
2931
2940
- <example>
2941
- <title>Lack of Casting</title>
2942
2932
<programlisting>
2943
2933
CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic');
2944
2934
CREATE TABLE holidays (
@@ -2954,15 +2944,12 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
2954
2944
WHERE person.current_mood = holidays.happiness;
2955
2945
ERROR: operator does not exist: mood = happiness
2956
2946
</programlisting>
2957
- </example >
2947
+ </para >
2958
2948
2959
2949
<para>
2960
2950
If you really need to do something like that, you can either
2961
2951
write a custom operator or add explicit casts to your query:
2962
- </para>
2963
2952
2964
- <example>
2965
- <title>Comparing Different Enums by Casting to Text</title>
2966
2953
<programlisting>
2967
2954
SELECT person.name, holidays.num_weeks FROM person, holidays
2968
2955
WHERE person.current_mood::text = holidays.happiness::text;
@@ -2972,7 +2959,7 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
2972
2959
(1 row)
2973
2960
2974
2961
</programlisting>
2975
- </example >
2962
+ </para >
2976
2963
</sect2>
2977
2964
2978
2965
<sect2>
0 commit comments