Re-add type conversion examples.
authorBruce Momjian
Thu, 20 Mar 2003 16:17:32 +0000 (16:17 +0000)
committerBruce Momjian
Thu, 20 Mar 2003 16:17:32 +0000 (16:17 +0000)
doc/src/sgml/typeconv.sgml

index f17e2e5c9a3e574690eb186a4b534b7b19833a2f..3aaffdc05dc40225ad94207058b836ff34fddbce 100644 (file)
@@ -1,5 +1,5 @@
 
 
 
@@ -403,6 +403,57 @@ type to resolve the unknown literals to.
 
 
 
+
+Absolute-Value and Factorial Operator Type Resolution
+
+
+The PostgreSQL operator catalog has several
+entries for the prefix operator @, all of which implement
+absolute-value operations for various numeric data types.  One of these
+entries is for type float8, which is the preferred type in
+the numeric category.  Therefore, PostgreSQL
+will use that entry when faced with a non-numeric input:
+
+SELECT @ '-4.5' AS "abs";
+ abs
+-----
+ 4.5
+(1 row)
+
+Here the system has performed an implicit conversion from text to float8
+before applying the chosen operator.  We can verify that float8 and
+not some other type was used:
+
+SELECT @ '-4.5e500' AS "abs";
+
+ERROR:  Input '-4.5e500' is out of range for float8
+
+
+
+
+On the other hand, the postfix operator ! (factorial)
+is defined only for integer data types, not for float8.  So, if we
+try a similar case with !, we get:
+
+SELECT '20' ! AS "factorial";
+
+ERROR:  Unable to identify a postfix operator '!' for type 'text'
+        You may need to add parentheses or an explicit cast
+
+This happens because the system can't decide which of the several
+possible ! operators should be preferred.  We can help
+it out with an explicit cast:
+
+SELECT CAST('20' AS int8) ! AS "factorial";
+
+      factorial
+---------------------
+ 2432902008176640000
+(1 row)
+
+
+
+