1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-20 05:03:10 +03:00

<example> is a floating element, so it's use is inappropriate when the

surrounding text refers to the example inline.
This commit is contained in:
Peter Eisentraut
2010-08-10 20:41:28 +00:00
parent 65559c385d
commit e0e08d3c80

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.250.2.4 2010/07/29 19:34:36 petere Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.250.2.5 2010/08/10 20:41:28 petere Exp $ -->
<chapter id="datatype">
<title>Data Types</title>
@ -2869,10 +2869,6 @@ CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
Once created, the enum type can be used in table and function
definitions much like any other type:
</para>
<example>
<title>Basic Enum Usage</title>
<programlisting>
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE person (
@ -2886,7 +2882,7 @@ SELECT * FROM person WHERE current_mood = 'happy';
Moe | happy
(1 row)
</programlisting>
</example>
</para>
</sect2>
<sect2>
@ -2897,10 +2893,7 @@ SELECT * FROM person WHERE current_mood = 'happy';
order in which the values were listed when the type was created.
All standard comparison operators and related
aggregate functions are supported for enums. For example:
</para>
<example>
<title>Enum Ordering</title>
<programlisting>
INSERT INTO person VALUES ('Larry', 'sad');
INSERT INTO person VALUES ('Curly', 'ok');
@ -2926,7 +2919,7 @@ WHERE current_mood = (SELECT MIN(current_mood) FROM person);
Larry
(1 row)
</programlisting>
</example>
</para>
</sect2>
<sect2>
@ -2934,11 +2927,8 @@ WHERE current_mood = (SELECT MIN(current_mood) FROM person);
<para>
Each enumerated data type is separate and cannot
be compared with other enumerated types.
</para>
be compared with other enumerated types. See this example:
<example>
<title>Lack of Casting</title>
<programlisting>
CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic');
CREATE TABLE holidays (
@ -2954,15 +2944,12 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
WHERE person.current_mood = holidays.happiness;
ERROR: operator does not exist: mood = happiness
</programlisting>
</example>
</para>
<para>
If you really need to do something like that, you can either
write a custom operator or add explicit casts to your query:
</para>
<example>
<title>Comparing Different Enums by Casting to Text</title>
<programlisting>
SELECT person.name, holidays.num_weeks FROM person, holidays
WHERE person.current_mood::text = holidays.happiness::text;
@ -2972,7 +2959,7 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
(1 row)
</programlisting>
</example>
</para>
</sect2>
<sect2>