aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-03-19 00:15:39 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-03-19 00:15:39 +0000
commitf11d253e25fccc93704803d0840a8e7ada46249e (patch)
treec58f0c76970b56f6db92bcf920f51800bbbe6f4a /src
parent7d392f257bb4d6099faf28f15c158a978a41f011 (diff)
downloadpostgresql-f11d253e25fccc93704803d0840a8e7ada46249e.tar.gz
postgresql-f11d253e25fccc93704803d0840a8e7ada46249e.zip
In can_coerce_type, verify that a possible type-coercion function
actually returns the type it is named for.
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/parse_coerce.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index f37082a87f5..35312eaadf0 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -8,13 +8,13 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.36 2000/03/16 06:35:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.37 2000/03/19 00:15:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-
+#include "catalog/pg_proc.h"
#include "optimizer/clauses.h"
#include "parser/parse_coerce.h"
#include "parser/parse_expr.h"
@@ -126,6 +126,12 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
result = transformExpr(pstate, (Node *) n, EXPR_COLUMN_FIRST);
+ /* safety check that we got the right thing */
+ if (exprType(result) != targetTypeId)
+ elog(ERROR, "coerce_type: conversion function %s produced %s",
+ typeTypeName(targetType),
+ typeidTypeName(exprType(result)));
+
/*
* If the input is a constant, apply the type conversion function
* now instead of delaying to runtime. (We could, of course,
@@ -163,6 +169,7 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids)
{
int i;
HeapTuple ftup;
+ Form_pg_proc pform;
Oid oid_array[FUNC_MAX_ARGS];
/* run through argument list... */
@@ -221,9 +228,10 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids)
0);
if (!HeapTupleIsValid(ftup))
return false;
- /*
- * should also check the function return type just to be safe...
- */
+ /* Make sure the function's result type is as expected, too */
+ pform = (Form_pg_proc) GETSTRUCT(ftup);
+ if (pform->prorettype != targetTypeId)
+ return false;
}
return true;