From 092bc4965378840479e0250ae679e1d8e86577ee Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas
Date: Fri, 31 Oct 2008 08:39:22 +0000
Subject: Add support for user-defined I/O conversion casts.
---
doc/src/sgml/catalogs.sgml | 23 +++++++++++++++++------
doc/src/sgml/ref/create_cast.sgml | 38 +++++++++++++++++++++++++++++---------
2 files changed, 46 insertions(+), 15 deletions(-)
(limited to 'doc/src')
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index a68799334a..faee42ba10 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -1,4 +1,4 @@
-
+
@@ -1415,9 +1415,10 @@
cannot be deduced from some generic rule. For example, casting between a
domain and its base type is not explicitly represented in
pg_cast. Another important exception is that
- I/O conversion casts>, those performed using a data type's own
- I/O functions to convert to or from text> or other string types,
- are not explicitly represented in pg_cast.
+ automatic I/O conversion casts>, those performed using a data
+ type's own I/O functions to convert to or from text> or other
+ string types, are not explicitly represented in
+ pg_cast.
@@ -1454,8 +1455,7 @@
pg_proc.oid
The OID of the function to use to perform this cast. Zero is
- stored if the data types are binary coercible (that is, no
- run-time operation is needed to perform the cast)
+ stored if the cast method doesn't require a function.
@@ -1473,6 +1473,17 @@
other cases
+
+ castmethod
+ char
+
+
+ Indicates how the cast is performed.
+ f> means that the function specified in the castfunc> field is used.
+ i> means that the input/output functions are used.
+ b> means that the types are binary-coercible, thus no conversion is required
+
+
diff --git a/doc/src/sgml/ref/create_cast.sgml b/doc/src/sgml/ref/create_cast.sgml
index 080f31832d..c771d22ad9 100644
--- a/doc/src/sgml/ref/create_cast.sgml
+++ b/doc/src/sgml/ref/create_cast.sgml
@@ -1,4 +1,4 @@
-
+
@@ -24,6 +24,10 @@ CREATE CAST (sourcetype AS targettypesourcetype AS targettype)
WITHOUT FUNCTION
[ AS ASSIGNMENT | AS IMPLICIT ]
+
+CREATE CAST (sourcetype AS targettype)
+ WITH INOUT
+ [ AS ASSIGNMENT | AS IMPLICIT ]
@@ -58,6 +62,13 @@ SELECT CAST(42 AS float8);
binary compatible.)
+
+ You can define a cast as an I/O conversion cast> using
+ the WITH INOUT syntax. An I/O conversion cast is
+ performed by invoking the output function of the source data type, and
+ passing the result to the input function of the target data type.
+
+
By default, a cast can be invoked only by an explicit cast request,
that is an explicit CAST(x> AS
@@ -199,6 +210,18 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
+
+ WITH INOUT
+
+
+
+ Indicates that the cast is an I/O conversion cast, performed by
+ invoking the output function of the source data type, and passing the
+ result to the input function of the target data type.
+
+
+
+
AS ASSIGNMENT
@@ -284,15 +307,12 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
It is normally not necessary to create casts between user-defined types
and the standard string types (text>, varchar>, and
char(n>), as well as user-defined types that
- are defined to be in the string category). PostgreSQL> will
- automatically handle a cast to a string type by invoking the other
- type's output function, or conversely handle a cast from a string type
- by invoking the other type's input function. These
- automatically-provided casts are known as I/O conversion
- casts>. I/O conversion casts to string types are treated as
- assignment casts, while I/O conversion casts from string types are
+ are defined to be in the string category). PostgreSQL>
+ provides automatic I/O conversion casts for that. The automatic casts to
+ string types are treated as assignment casts, while the automatic casts
+ from string types are
explicit-only. You can override this behavior by declaring your own
- cast to replace an I/O conversion cast, but usually the only reason to
+ cast to replace an automatic cast, but usually the only reason to
do so is if you want the conversion to be more easily invokable than the
standard assignment-only or explicit-only setting. Another possible
reason is that you want the conversion to behave differently from the
--
cgit v1.2.3