Am Mittwoch, 9. Juli 2008 schrieb Peter Eisentraut:
> I propose that we relax these two checks to test for binary-coercibility
> instead, which is effectively what is expected and required here anyway.
Here is the corresponding patch.
diff -ur ../cvs-pgsql/doc/src/sgml/ref/create_cast.sgml ./doc/src/sgml/ref/create_cast.sgml
--- ../cvs-pgsql/doc/src/sgml/ref/create_cast.sgml 2007-07-10 14:57:00.000000000 +0200
+++ ./doc/src/sgml/ref/create_cast.sgml 2008-07-10 14:07:27.000000000 +0200
@@ -205,7 +205,7 @@
<para>
Cast implementation functions can have one to three arguments.
- The first argument type must be identical to the cast's source type.
+ The first argument type must be identical to or binary-compatible with the cast's source type.
The second argument,
if present, must be type <type>integer</>; it receives the type
modifier associated with the destination type, or <literal>-1</>
diff -ur ../cvs-pgsql/src/backend/commands/functioncmds.c ./src/backend/commands/functioncmds.c
--- ../cvs-pgsql/src/backend/commands/functioncmds.c 2008-07-03 16:53:04.000000000 +0200
+++ ./src/backend/commands/functioncmds.c 2008-07-10 13:42:26.000000000 +0200
@@ -48,6 +48,7 @@
#include "commands/defrem.h"
#include "commands/proclang.h"
#include "miscadmin.h"
+#include "parser/parse_coerce.h"
#include "parser/parse_func.h"
#include "parser/parse_type.h"
#include "utils/acl.h"
@@ -1403,10 +1404,10 @@
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("cast function must take one to three arguments")));
- if (procstruct->proargtypes.values[0] != sourcetypeid)
+ if (!IsBinaryCoercible(sourcetypeid, procstruct->proargtypes.values[0]))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("argument of cast function must match source data type")));
+ errmsg("argument of cast function must match or be binary-compatible with source data type")));
if (nargs > 1 && procstruct->proargtypes.values[1] != INT4OID)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
@@ -1415,10 +1416,10 @@
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("third argument of cast function must be type boolean")));
- if (procstruct->prorettype != targettypeid)
+ if (!IsBinaryCoercible(procstruct->prorettype, targettypeid))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("return data type of cast function must match target data type")));
+ errmsg("return data type of cast function must match or be binary-compatible with target data type")));
/*
* Restricting the volatility of a cast function may or may not be a
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers