Am Montag, 2. April 2007 18:41 schrieb Tom Lane: > >> The scheme that was in the back of my mind was to do this at the same > >> time as providing a general facility for casting *every* type to and > >> from text, by means of their I/O functions if no specialized cast is > >> provided in pg_cast.
> http://archives.postgresql.org/pgsql-admin/2004-06/msg00390.php > http://archives.postgresql.org/pgsql-hackers/2004-10/msg00303.php FWIW, is the attached patch about what you had in mind? (It probably only covers "normal" types at the moment.) -- Peter Eisentraut http://developer.postgresql.org/~petere/
diff -ur ../cvs-pgsql/src/backend/parser/parse_coerce.c ./src/backend/parser/parse_coerce.c --- ../cvs-pgsql/src/backend/parser/parse_coerce.c 2007-04-02 08:52:16.000000000 +0200 +++ ./src/backend/parser/parse_coerce.c 2007-04-03 18:05:12.000000000 +0200 @@ -371,6 +371,28 @@ r->convertformat = cformat; return (Node *) r; } + if ((inputTypeId == TEXTOID || targetTypeId == TEXTOID) && ccontext == COERCION_EXPLICIT) + { + /* Explicit coercion through I/O functions */ + Oid inputTypeOutput; + Oid targetTypeInput; + bool isVarlena; + Oid typeIOParam; + + getTypeInputInfo(targetTypeId, &targetTypeInput, &typeIOParam); + getTypeOutputInfo(inputTypeId, &inputTypeOutput, &isVarlena); + + result = build_coercion_expression(build_coercion_expression(node, inputTypeOutput, arrayCoerce, + CSTRINGOID, -1, + cformat, + (cformat != COERCE_IMPLICIT_CAST)), + targetTypeInput, arrayCoerce, + targetTypeId, -1, + cformat, + (cformat != COERCE_IMPLICIT_CAST)); + + return result; + } /* If we get here, caller blew it */ elog(ERROR, "failed to find conversion function from %s to %s", format_type_be(inputTypeId), format_type_be(targetTypeId)); @@ -451,6 +473,10 @@ if (typeInheritsFrom(inputTypeId, targetTypeId)) continue; + /* Else only explicit coercion from/to text is possible through I/O functions */ + if ((inputTypeId == TEXTOID || targetTypeId == TEXTOID) && ccontext == COERCION_EXPLICIT) + continue; + /* * Else, cannot coerce at this argument position */
---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend