1- <!-- $PostgreSQL: pgsql/doc/src/sgml/ref/create_cast.sgml,v 1.26 2007/06/05 21:31:04 tgl Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/ref/create_cast.sgml,v 1.27 2008/07/11 07:02:43 petere Exp $ -->
22
33<refentry id="SQL-CREATECAST">
44 <refmeta>
@@ -44,12 +44,18 @@ SELECT CAST(42 AS float8);
4444 </para>
4545
4646 <para>
47- Two types can be <firstterm>binary compatible</firstterm>, which
48- means that they can be converted into one another <quote>for
49- free</quote> without invoking any function. This requires that
50- corresponding values use the same internal representation. For
51- instance, the types <type>text</type> and <type>varchar</type> are
52- binary compatible.
47+ Two types can be <firstterm>binary coercible</firstterm>, which
48+ means that the conversion can be performed <quote>for free</quote>
49+ without invoking any function. This requires that corresponding
50+ values use the same internal representation. For instance, the
51+ types <type>text</type> and <type>varchar</type> are binary
52+ coercible both ways. Binary coercibility is not necessarily a
53+ symmetric relationship. For example, the cast
54+ from <type>xml</type> to <type>text</type> can be performed for
55+ free in the present implementation, but the reverse direction
56+ requires a function that performs at least a syntax check. (Two
57+ types that are binary coercible both ways are also referred to as
58+ binary compatible.)
5359 </para>
5460
5561 <para>
@@ -127,8 +133,8 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
127133
128134 <para>
129135 To be able to create a cast, you must own the source or the target
130- data type. To create a binary-compatible cast, you must be superuser.
131- (This restriction is made because an erroneous binary-compatible cast
136+ data type. To create a binary-coercible cast, you must be superuser.
137+ (This restriction is made because an erroneous binary-coercible cast
132138 conversion can easily crash the server.)
133139 </para>
134140 </refsect1>
@@ -176,7 +182,7 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
176182 <listitem>
177183 <para>
178184 Indicates that the source type and the target type are binary
179- compatible , so no function is required to perform the cast.
185+ coercible , so no function is required to perform the cast.
180186 </para>
181187 </listitem>
182188 </varlistentry>
@@ -205,8 +211,8 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
205211
206212 <para>
207213 Cast implementation functions can have one to three arguments.
208- The first argument type must be identical tothe cast's source type.
209- The second argument,
214+ The first argument type must be identical toor binary-coercible from
215+ the cast's source type. The second argument,
210216 if present, must be type <type>integer</>; it receives the type
211217 modifier associated with the destination type, or <literal>-1</>
212218 if there is none. The third argument,
@@ -218,6 +224,11 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
218224 your own data types so that this matters.)
219225 </para>
220226
227+ <para>
228+ The return type of a cast function must be identical to or
229+ binary-coercible to the cast's target type.
230+ </para>
231+
221232 <para>
222233 Ordinarily a cast must have different source and target data types.
223234 However, it is allowed to declare a cast with identical source and
@@ -311,10 +322,10 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
311322 request without having matched it to an actual function.
312323 If a function call <replaceable>name</>(<replaceable>x</>) does not
313324 exactly match any existing function, but <replaceable>name</> is the name
314- of a data type and <structname>pg_cast</> provides a binary-compatible cast
325+ of a data type and <structname>pg_cast</> provides a binary-coercible cast
315326 to this type from the type of <replaceable>x</>, then the call will be
316327 construed as a binary-compatible cast. This exception is made so that
317- binary-compatible casts can be invoked using functional syntax, even
328+ binary-coercible casts can be invoked using functional syntax, even
318329 though they lack any function. Likewise, if there is no
319330 <structname>pg_cast</> entry but the cast would be to or from a string
320331 type, the call will be construed as an I/O conversion cast. This
@@ -345,7 +356,7 @@ CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint);
345356 <para>
346357 The <command>CREATE CAST</command> command conforms to the
347358 <acronym>SQL</acronym> standard,
348- except that SQL does not make provisions for binary-compatible
359+ except that SQL does not make provisions for binary-coercible
349360 types or extra arguments to implementation functions.
350361 <literal>AS IMPLICIT</> is a <productname>PostgreSQL</productname>
351362 extension, too.