1- <!-- $PostgreSQL: pgsql/doc/src/sgml/ref/create_cast.sgml,v 1.28 2008/07/12 16:20:06 tgl Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/ref/create_cast.sgml,v 1.29 2008/07/30 21:23:17 tgl Exp $ -->
22
33<refentry id="SQL-CREATECAST">
44 <refmeta>
@@ -26,7 +26,7 @@ CREATE CAST (<replaceable>sourcetype</replaceable> AS <replaceable>targettype</r
2626 [ AS ASSIGNMENT | AS IMPLICIT ]
2727</synopsis>
2828 </refsynopsisdiv>
29-
29+
3030 <refsect1 id="sql-createcast-description">
3131 <title>Description</title>
3232
@@ -131,6 +131,18 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
131131 to <type>int4</>, are best made explicit-only.
132132 </para>
133133
134+ <note>
135+ <para>
136+ Sometimes it is necessary for usability or standards-compliance reasons
137+ to provide multiple implicit casts among a set of types, resulting in
138+ ambiguity that cannot be avoided as above. The parser has a fallback
139+ heuristic based on <firstterm>type categories</> and <firstterm>preferred
140+ types</> that can help to provide desired behavior in such cases. See
141+ <xref linkend="sql-createtype" endterm="sql-createtype-title"> for
142+ more information.
143+ </para>
144+ </note>
145+
134146 <para>
135147 To be able to create a cast, you must own the source or the target
136148 data type. To create a binary-coercible cast, you must be superuser.
@@ -181,8 +193,8 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
181193
182194 <listitem>
183195 <para>
184- Indicates that the source typeand the target type are binary
185- coercible, so no function is required to perform the cast.
196+ Indicates that the source typeis binary-coercible to the target type,
197+ so no function is required to perform the cast.
186198 </para>
187199 </listitem>
188200 </varlistentry>
@@ -218,7 +230,7 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
218230 if there is none. The third argument,
219231 if present, must be type <type>boolean</>; it receives <literal>true</>
220232 if the cast is an explicit cast, <literal>false</> otherwise.
221- (Bizarrely, the SQLspec demands different behaviors for explicit and
233+ (Bizarrely, the SQLstandard demands different behaviors for explicit and
222234 implicit casts in some cases. This argument is supplied for functions
223235 that must implement such casts. It is not recommended that you design
224236 your own data types so that this matters.)
@@ -271,7 +283,8 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
271283 <para>
272284 It is normally not necessary to create casts between user-defined types
273285 and the standard string types (<type>text</>, <type>varchar</>, and
274- <type>char(<replaceable>n</>)</type>). <productname>PostgreSQL</> will
286+ <type>char(<replaceable>n</>)</type>, as well as user-defined types that
287+ are defined to be in the string category). <productname>PostgreSQL</> will
275288 automatically handle a cast to a string type by invoking the other
276289 type's output function, or conversely handle a cast from a string type
277290 by invoking the other type's input function. These
@@ -340,16 +353,15 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
340353 <title>Examples</title>
341354
342355 <para>
343- To createa cast from type <type>bigint</type> to type
356+ To createan assignment cast from type <type>bigint</type> to type
344357 <type>int4</type> using the function <literal>int4(bigint)</literal>:
345358<programlisting>
346- CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint);
359+ CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint) AS ASSIGNMENT ;
347360</programlisting>
348361 (This cast is already predefined in the system.)
349362 </para>
350363 </refsect1>
351364
352-
353365 <refsect1 id="sql-createcast-compat">
354366 <title>Compatibility</title>
355367
@@ -358,7 +370,7 @@ CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint);
358370 <acronym>SQL</acronym> standard,
359371 except that SQL does not make provisions for binary-coercible
360372 types or extra arguments to implementation functions.
361- <literal>AS IMPLICIT</> is a <productname>PostgreSQL</productname>
373+ <literal>AS IMPLICIT</> is a <productname>PostgreSQL</productname>
362374 extension, too.
363375 </para>
364376 </refsect1>