|
1 | 1 | <!-- |
2 | | -$Header: /cvsroot/pgsql/doc/src/sgml/typeconv.sgml,v 1.27 2003/03/13 01:30:29 petere Exp $ |
| 2 | +$Header: /cvsroot/pgsql/doc/src/sgml/typeconv.sgml,v 1.28 2003/03/19 21:20:52 momjian Exp $ |
3 | 3 | --> |
4 | 4 |
|
5 | 5 | <chapter Id="typeconv"> |
@@ -403,57 +403,6 @@ type to resolve the unknown literals to. |
403 | 403 | </para> |
404 | 404 | </example> |
405 | 405 |
|
406 | | -<example> |
407 | | -<title>Absolute-Value and Factorial Operator Type Resolution</title> |
408 | | - |
409 | | -<para> |
410 | | -The <productname>PostgreSQL</productname> operator catalog has several |
411 | | -entries for the prefix operator <literal>@</>, all of which implement |
412 | | -absolute-value operations for various numeric data types. One of these |
413 | | -entries is for type <type>float8</type>, which is the preferred type in |
414 | | -the numeric category. Therefore, <productname>PostgreSQL</productname> |
415 | | -will use that entry when faced with a non-numeric input: |
416 | | -<screen> |
417 | | -SELECT @ '-4.5' AS "abs"; |
418 | | - abs |
419 | | ------ |
420 | | - 4.5 |
421 | | -(1 row) |
422 | | -</screen> |
423 | | -Here the system has performed an implicit conversion from <type>text</type> to <type>float8</type> |
424 | | -before applying the chosen operator. We can verify that <type>float8</type> and |
425 | | -not some other type was used: |
426 | | -<screen> |
427 | | -SELECT @ '-4.5e500' AS "abs"; |
428 | | - |
429 | | -ERROR: Input '-4.5e500' is out of range for float8 |
430 | | -</screen> |
431 | | -</para> |
432 | | - |
433 | | -<para> |
434 | | -On the other hand, the postfix operator <literal>!</> (factorial) |
435 | | -is defined only for integer data types, not for <type>float8</type>. So, if we |
436 | | -try a similar case with <literal>!</>, we get: |
437 | | -<screen> |
438 | | -SELECT '20' ! AS "factorial"; |
439 | | - |
440 | | -ERROR: Unable to identify a postfix operator '!' for type 'text' |
441 | | - You may need to add parentheses or an explicit cast |
442 | | -</screen> |
443 | | -This happens because the system can't decide which of the several |
444 | | -possible <literal>!</> operators should be preferred. We can help |
445 | | -it out with an explicit cast: |
446 | | -<screen> |
447 | | -SELECT CAST('20' AS int8) ! AS "factorial"; |
448 | | - |
449 | | - factorial |
450 | | ---------------------- |
451 | | - 2432902008176640000 |
452 | | -(1 row) |
453 | | -</screen> |
454 | | -</para> |
455 | | -</example> |
456 | | - |
457 | 406 | </sect1> |
458 | 407 |
|
459 | 408 | <sect1 id="typeconv-func"> |
|