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.c101
1 files changed, 12 insertions, 89 deletions
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index 5670ed4fe74..45c8e97be1d 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.148 2006/12/21 16:05:14 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.149 2006/12/24 00:29:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -840,8 +840,8 @@ coerce_to_boolean(ParseState *pstate, Node *node,
}
/*
- * coerce_to_integer()
- * Coerce an argument of a construct that requires integer input.
+ * coerce_to_specific_type()
+ * Coerce an argument of a construct that requires a specific data type.
* Also check that input is not a set.
*
* Returns the possibly-transformed node tree.
@@ -850,103 +850,26 @@ coerce_to_boolean(ParseState *pstate, Node *node,
* processing is wanted.
*/
Node *
-coerce_to_integer(ParseState *pstate, Node *node,
- const char *constructName)
-{
- Oid inputTypeId = exprType(node);
-
- if (inputTypeId != INT4OID)
- {
- node = coerce_to_target_type(pstate, node, inputTypeId,
- INT4OID, -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 integer, 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;
-}
-
-/*
- * coerce_to_bigint()
- * Coerce an argument of a construct that requires int8 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_bigint(ParseState *pstate, Node *node,
- const char *constructName)
-{
- Oid inputTypeId = exprType(node);
-
- if (inputTypeId != INT8OID)
- {
- node = coerce_to_target_type(pstate, node, inputTypeId,
- INT8OID, -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 bigint, 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;
-}
-
-/*
- * 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)
+coerce_to_specific_type(ParseState *pstate, Node *node,
+ Oid targetTypeId,
+ const char *constructName)
{
Oid inputTypeId = exprType(node);
- if (inputTypeId != XMLOID)
+ if (inputTypeId != targetTypeId)
{
node = coerce_to_target_type(pstate, node, inputTypeId,
- XMLOID, -1,
+ targetTypeId, -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))));
+ errmsg("argument of %s must be type %s, not type %s",
+ constructName,
+ format_type_be(targetTypeId),
+ format_type_be(inputTypeId))));
}
if (expression_returns_set(node))