summaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_coerce.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/parser/parse_coerce.c')
-rw-r--r--src/backend/parser/parse_coerce.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index 2a468c68271..5670ed4fe74 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.147 2006/12/10 22:13:26 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.148 2006/12/21 16:05:14 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -919,6 +919,46 @@ coerce_to_bigint(ParseState *pstate, Node *node,
return node;
}
+/*
+ * coerce_to_xml()
+ * Coerce an argument of a construct that requires xml input.
+ * Also check that input is not a set.
+ *
+ * Returns the possibly-transformed node tree.
+ *
+ * As with coerce_type, pstate may be NULL if no special unknown-Param
+ * processing is wanted.
+ */
+Node *
+coerce_to_xml(ParseState *pstate, Node *node,
+ const char *constructName)
+{
+ Oid inputTypeId = exprType(node);
+
+ if (inputTypeId != XMLOID)
+ {
+ node = coerce_to_target_type(pstate, node, inputTypeId,
+ XMLOID, -1,
+ COERCION_ASSIGNMENT,
+ COERCE_IMPLICIT_CAST);
+ if (node == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ /* translator: first %s is name of a SQL construct, eg LIMIT */
+ errmsg("argument of %s must be type xml, not type %s",
+ constructName, format_type_be(inputTypeId))));
+ }
+
+ if (expression_returns_set(node))
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ /* translator: %s is name of a SQL construct, eg LIMIT */
+ errmsg("argument of %s must not return a set",
+ constructName)));
+
+ return node;
+}
+
/* select_common_type()
* Determine the common supertype of a list of input expression types.