From 03b0a589d1d43c91224bc148d50c3242c6776058 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 4 Oct 2001 22:06:46 +0000 Subject: Consider interpreting a function call as a trivial (binary-compatible) type coercion after failing to find an exact match in pg_proc, but before considering interpretations that involve a function call with one or more argument type coercions. This avoids surprises wherein what looks like a type coercion is interpreted as coercing to some third type and then to the destination type, as in Dave Blasby's bug report of 3-Oct-01. See subsequent discussion in pghackers. --- src/backend/commands/indexcmds.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/backend/commands/indexcmds.c') diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 2304dd0b0cd..aaf0630a2a7 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.57 2001/08/21 16:36:02 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.58 2001/10/04 22:06:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -240,6 +240,7 @@ FuncIndexArgs(IndexInfo *indexInfo, List *arglist; int nargs = 0; int i; + FuncDetailCode fdresult; Oid funcid; Oid rettype; bool retset; @@ -282,9 +283,18 @@ FuncIndexArgs(IndexInfo *indexInfo, * that. So, check to make sure that the selected function has * exact-match or binary-compatible input types. */ - if (!func_get_detail(funcIndex->name, nargs, argTypes, - &funcid, &rettype, &retset, &true_typeids)) - func_error("DefineIndex", funcIndex->name, nargs, argTypes, NULL); + fdresult = func_get_detail(funcIndex->name, funcIndex->args, + nargs, argTypes, + &funcid, &rettype, &retset, + &true_typeids); + if (fdresult != FUNCDETAIL_NORMAL) + { + if (fdresult == FUNCDETAIL_COERCION) + elog(ERROR, "DefineIndex: functional index must use a real function, not a type coercion" + "\n\tTry specifying the index opclass you want to use, instead"); + else + func_error("DefineIndex", funcIndex->name, nargs, argTypes, NULL); + } if (retset) elog(ERROR, "DefineIndex: cannot index on a function returning a set"); -- cgit v1.2.3