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 $ -->
2
2
3
3
<refentry id="SQL-CREATECAST">
4
4
<refmeta>
@@ -26,7 +26,7 @@ CREATE CAST (<replaceable>sourcetype</replaceable> AS <replaceable>targettype</r
26
26
[ AS ASSIGNMENT | AS IMPLICIT ]
27
27
</synopsis>
28
28
</refsynopsisdiv>
29
-
29
+
30
30
<refsect1 id="sql-createcast-description">
31
31
<title>Description</title>
32
32
@@ -131,6 +131,18 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
131
131
to <type>int4</>, are best made explicit-only.
132
132
</para>
133
133
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
+
134
146
<para>
135
147
To be able to create a cast, you must own the source or the target
136
148
data type. To create a binary-coercible cast, you must be superuser.
@@ -181,8 +193,8 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
181
193
182
194
<listitem>
183
195
<para>
184
- Indicates that the source type and the target type are binary
185
- coercible, so no function is required to perform the cast.
196
+ Indicates that the source type is binary-coercible to the target type,
197
+ so no function is required to perform the cast.
186
198
</para>
187
199
</listitem>
188
200
</varlistentry>
@@ -218,7 +230,7 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
218
230
if there is none. The third argument,
219
231
if present, must be type <type>boolean</>; it receives <literal>true</>
220
232
if the cast is an explicit cast, <literal>false</> otherwise.
221
- (Bizarrely, the SQL spec demands different behaviors for explicit and
233
+ (Bizarrely, the SQL standard demands different behaviors for explicit and
222
234
implicit casts in some cases. This argument is supplied for functions
223
235
that must implement such casts. It is not recommended that you design
224
236
your own data types so that this matters.)
@@ -271,7 +283,8 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
271
283
<para>
272
284
It is normally not necessary to create casts between user-defined types
273
285
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
275
288
automatically handle a cast to a string type by invoking the other
276
289
type's output function, or conversely handle a cast from a string type
277
290
by invoking the other type's input function. These
@@ -340,16 +353,15 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
340
353
<title>Examples</title>
341
354
342
355
<para>
343
- To create a cast from type <type>bigint</type> to type
356
+ To create an assignment cast from type <type>bigint</type> to type
344
357
<type>int4</type> using the function <literal>int4(bigint)</literal>:
345
358
<programlisting>
346
- CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint);
359
+ CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint) AS ASSIGNMENT ;
347
360
</programlisting>
348
361
(This cast is already predefined in the system.)
349
362
</para>
350
363
</refsect1>
351
364
352
-
353
365
<refsect1 id="sql-createcast-compat">
354
366
<title>Compatibility</title>
355
367
@@ -358,7 +370,7 @@ CREATE CAST (bigint AS int4) WITH FUNCTION int4(bigint);
358
370
<acronym>SQL</acronym> standard,
359
371
except that SQL does not make provisions for binary-coercible
360
372
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>
362
374
extension, too.
363
375
</para>
364
376
</refsect1>
0 commit comments