From: Tom Lane Date: Fri, 29 Aug 2008 17:27:50 +0000 (+0000) Subject: Fix bug in original implementation of xmlserialize(): if user specifies X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=85525650c69a08b4c19904d21acd96821b9c3709;p=users%2Fbernd%2Fpostgres.git Fix bug in original implementation of xmlserialize(): if user specifies a target type that isn't acceptable, the code failed to raise the proper error. The result instead was to return a NULL expression tree, which in a quick test led to a 'cache lookup failed for type 0' error later. Patch 8.3 only --- I fixed this in HEAD as part of recent locations patch. --- diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index ef7d403ed4..6bb5f81333 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -1539,9 +1539,10 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x) static Node * transformXmlSerialize(ParseState *pstate, XmlSerialize *xs) { + Node *result; + XmlExpr *xexpr; Oid targetType; int32 targetTypmod; - XmlExpr *xexpr; xexpr = makeNode(XmlExpr); xexpr->op = IS_XMLSERIALIZE; @@ -1563,8 +1564,15 @@ transformXmlSerialize(ParseState *pstate, XmlSerialize *xs) * from text. This way, user-defined text-like data types automatically * fit in. */ - return (Node *) coerce_to_target_type(pstate, (Node *) xexpr, TEXTOID, targetType, targetTypmod, - COERCION_IMPLICIT, COERCE_IMPLICIT_CAST); + result = coerce_to_target_type(pstate, (Node *) xexpr, + TEXTOID, targetType, targetTypmod, + COERCION_IMPLICIT, COERCE_IMPLICIT_CAST); + if (result == NULL) + ereport(ERROR, + (errcode(ERRCODE_CANNOT_COERCE), + errmsg("cannot cast XMLSERIALIZE result to %s", + format_type_be(targetType)))); + return result; } static Node *