]> granicus.if.org Git - postgresql/commitdiff
Fix bug in original implementation of xmlserialize(): if user specifies
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 29 Aug 2008 17:27:50 +0000 (17:27 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 29 Aug 2008 17:27:50 +0000 (17:27 +0000)
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.

src/backend/parser/parse_expr.c

index d43d38c494d91d4daea78a6094c47b2048640a18..e174325c5e03f96688c3ce5bd0d0ab02539456a6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.226 2008/01/01 19:45:50 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.226.2.1 2008/08/29 17:27:50 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 *