1- <!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.255 2010/07/29 19:34:40 petere Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.256 2010/08/10 20:41:27 petere Exp $ -->
22
33 <chapter id="datatype">
44 <title>Data Types</title>
@@ -2877,10 +2877,6 @@ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
28772877
28782878 Once created, the enum type can be used in table and function
28792879 definitions much like any other type:
2880- </para>
2881-
2882- <example>
2883- <title>Basic Enum Usage</title>
28842880<programlisting>
28852881CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
28862882CREATE TABLE person (
@@ -2894,7 +2890,7 @@ SELECT * FROM person WHERE current_mood = 'happy';
28942890 Moe | happy
28952891(1 row)
28962892</programlisting>
2897- </example >
2893+ </para >
28982894 </sect2>
28992895
29002896 <sect2>
@@ -2905,10 +2901,7 @@ SELECT * FROM person WHERE current_mood = 'happy';
29052901 order in which the values were listed when the type was created.
29062902 All standard comparison operators and related
29072903 aggregate functions are supported for enums. For example:
2908- </para>
2909-
2910- <example>
2911- <title>Enum Ordering</title>
2904+
29122905<programlisting>
29132906INSERT INTO person VALUES ('Larry', 'sad');
29142907INSERT INTO person VALUES ('Curly', 'ok');
@@ -2934,19 +2927,16 @@ WHERE current_mood = (SELECT MIN(current_mood) FROM person);
29342927 Larry
29352928(1 row)
29362929</programlisting>
2937- </example >
2930+ </para >
29382931 </sect2>
29392932
29402933 <sect2>
29412934 <title>Type Safety</title>
29422935
29432936 <para>
29442937 Each enumerated data type is separate and cannot
2945- be compared with other enumerated types.
2946- </para>
2938+ be compared with other enumerated types. See this example:
29472939
2948- <example>
2949- <title>Lack of Casting</title>
29502940<programlisting>
29512941CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic');
29522942CREATE TABLE holidays (
@@ -2962,15 +2952,12 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
29622952 WHERE person.current_mood = holidays.happiness;
29632953ERROR: operator does not exist: mood = happiness
29642954</programlisting>
2965- </example >
2955+ </para >
29662956
29672957 <para>
29682958 If you really need to do something like that, you can either
29692959 write a custom operator or add explicit casts to your query:
2970- </para>
29712960
2972- <example>
2973- <title>Comparing Different Enums by Casting to Text</title>
29742961<programlisting>
29752962SELECT person.name, holidays.num_weeks FROM person, holidays
29762963 WHERE person.current_mood::text = holidays.happiness::text;
@@ -2980,7 +2967,7 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
29802967(1 row)
29812968
29822969</programlisting>
2983- </example >
2970+ </para >
29842971 </sect2>
29852972
29862973 <sect2>