1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* pg_aggregate.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* routines to support manipulation of the pg_aggregate relation
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2006-03-05 16:59:11 +01:00
|
|
|
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2006-10-04 02:30:14 +02:00
|
|
|
* $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.83 2006/10/04 00:29:50 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "postgres.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/heapam.h"
|
2002-07-17 00:12:20 +02:00
|
|
|
#include "catalog/dependency.h"
|
1999-11-22 18:56:41 +01:00
|
|
|
#include "catalog/indexing.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "catalog/pg_aggregate.h"
|
2002-04-11 22:00:18 +02:00
|
|
|
#include "catalog/pg_language.h"
|
2005-04-14 22:03:27 +02:00
|
|
|
#include "catalog/pg_operator.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "catalog/pg_proc.h"
|
2006-07-13 18:49:20 +02:00
|
|
|
#include "catalog/pg_type.h"
|
2005-01-28 00:42:18 +01:00
|
|
|
#include "miscadmin.h"
|
2000-07-17 05:05:41 +02:00
|
|
|
#include "parser/parse_coerce.h"
|
|
|
|
#include "parser/parse_func.h"
|
2005-04-12 06:26:34 +02:00
|
|
|
#include "parser/parse_oper.h"
|
2005-01-28 00:42:18 +01:00
|
|
|
#include "utils/acl.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "utils/builtins.h"
|
2005-01-28 00:42:18 +01:00
|
|
|
#include "utils/lsyscache.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "utils/syscache.h"
|
1996-11-04 00:27:08 +01:00
|
|
|
|
2002-04-11 22:00:18 +02:00
|
|
|
|
2003-08-04 02:43:34 +02:00
|
|
|
static Oid lookup_agg_function(List *fnName, int nargs, Oid *input_types,
|
|
|
|
Oid *rettype);
|
2003-07-01 21:10:53 +02:00
|
|
|
|
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
/*
|
1996-07-09 08:22:35 +02:00
|
|
|
* AggregateCreate
|
|
|
|
*/
|
|
|
|
void
|
2002-03-29 20:06:29 +01:00
|
|
|
AggregateCreate(const char *aggName,
|
|
|
|
Oid aggNamespace,
|
2006-07-27 21:52:07 +02:00
|
|
|
Oid *aggArgTypes,
|
|
|
|
int numArgs,
|
2002-04-09 22:35:55 +02:00
|
|
|
List *aggtransfnName,
|
|
|
|
List *aggfinalfnName,
|
2005-04-12 06:26:34 +02:00
|
|
|
List *aggsortopName,
|
2002-03-29 20:06:29 +01:00
|
|
|
Oid aggTransType,
|
|
|
|
const char *agginitval)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Relation aggdesc;
|
|
|
|
HeapTuple tup;
|
|
|
|
char nulls[Natts_pg_aggregate];
|
|
|
|
Datum values[Natts_pg_aggregate];
|
|
|
|
Form_pg_proc proc;
|
2000-07-17 05:05:41 +02:00
|
|
|
Oid transfn;
|
2001-03-22 05:01:46 +01:00
|
|
|
Oid finalfn = InvalidOid; /* can be omitted */
|
2005-04-12 06:26:34 +02:00
|
|
|
Oid sortop = InvalidOid; /* can be omitted */
|
2006-07-27 21:52:07 +02:00
|
|
|
bool hasPolyArg;
|
2003-07-01 21:10:53 +02:00
|
|
|
Oid rettype;
|
2000-07-17 05:05:41 +02:00
|
|
|
Oid finaltype;
|
2006-07-27 21:52:07 +02:00
|
|
|
Oid *fnArgs;
|
2003-07-01 21:10:53 +02:00
|
|
|
int nargs_transfn;
|
2002-04-11 22:00:18 +02:00
|
|
|
Oid procOid;
|
1997-09-08 04:41:22 +02:00
|
|
|
TupleDesc tupDesc;
|
2000-07-17 05:05:41 +02:00
|
|
|
int i;
|
2002-09-04 22:31:48 +02:00
|
|
|
ObjectAddress myself,
|
|
|
|
referenced;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2003-07-21 03:59:11 +02:00
|
|
|
/* sanity checks (caller should have caught these) */
|
1997-09-07 07:04:48 +02:00
|
|
|
if (!aggName)
|
2001-08-10 17:49:39 +02:00
|
|
|
elog(ERROR, "no aggregate name supplied");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
if (!aggtransfnName)
|
2001-08-10 17:49:39 +02:00
|
|
|
elog(ERROR, "aggregate must have a transition function");
|
2000-03-26 21:43:58 +02:00
|
|
|
|
2006-07-27 21:52:07 +02:00
|
|
|
/* check for polymorphic arguments */
|
|
|
|
hasPolyArg = false;
|
|
|
|
for (i = 0; i < numArgs; i++)
|
|
|
|
{
|
|
|
|
if (aggArgTypes[i] == ANYARRAYOID ||
|
|
|
|
aggArgTypes[i] == ANYELEMENTOID)
|
|
|
|
{
|
|
|
|
hasPolyArg = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:10:53 +02:00
|
|
|
/*
|
2006-10-04 02:30:14 +02:00
|
|
|
* If transtype is polymorphic, must have polymorphic argument also; else
|
|
|
|
* we will have no way to deduce the actual transtype.
|
2003-07-01 21:10:53 +02:00
|
|
|
*/
|
2006-07-27 21:52:07 +02:00
|
|
|
if (!hasPolyArg &&
|
|
|
|
(aggTransType == ANYARRAYOID || aggTransType == ANYELEMENTOID))
|
2003-07-21 03:59:11 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
2003-09-25 08:58:07 +02:00
|
|
|
errmsg("cannot determine transition data type"),
|
2006-10-04 02:30:14 +02:00
|
|
|
errdetail("An aggregate using \"anyarray\" or \"anyelement\" as transition type must have at least one argument of either type.")));
|
2003-07-01 21:10:53 +02:00
|
|
|
|
2006-07-27 21:52:07 +02:00
|
|
|
/* find the transfn */
|
|
|
|
nargs_transfn = numArgs + 1;
|
|
|
|
fnArgs = (Oid *) palloc(nargs_transfn * sizeof(Oid));
|
2002-03-29 20:06:29 +01:00
|
|
|
fnArgs[0] = aggTransType;
|
2006-07-27 21:52:07 +02:00
|
|
|
memcpy(fnArgs + 1, aggArgTypes, numArgs * sizeof(Oid));
|
2003-07-01 21:10:53 +02:00
|
|
|
transfn = lookup_agg_function(aggtransfnName, nargs_transfn, fnArgs,
|
|
|
|
&rettype);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return type of transfn (possibly after refinement by
|
2005-10-15 04:49:52 +02:00
|
|
|
* enforce_generic_type_consistency, if transtype isn't polymorphic) must
|
|
|
|
* exactly match declared transtype.
|
2003-07-01 21:10:53 +02:00
|
|
|
*
|
2005-11-22 19:17:34 +01:00
|
|
|
* In the non-polymorphic-transtype case, it might be okay to allow a
|
|
|
|
* rettype that's binary-coercible to transtype, but I'm not quite
|
|
|
|
* convinced that it's either safe or useful. When transtype is
|
|
|
|
* polymorphic we *must* demand exact equality.
|
2003-07-01 21:10:53 +02:00
|
|
|
*/
|
|
|
|
if (rettype != aggTransType)
|
2003-07-21 03:59:11 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
|
|
|
errmsg("return type of transition function %s is not %s",
|
|
|
|
NameListToString(aggtransfnName),
|
|
|
|
format_type_be(aggTransType))));
|
2003-07-01 21:10:53 +02:00
|
|
|
|
2002-04-09 22:35:55 +02:00
|
|
|
tup = SearchSysCache(PROCOID,
|
|
|
|
ObjectIdGetDatum(transfn),
|
|
|
|
0, 0, 0);
|
2000-07-17 05:05:41 +02:00
|
|
|
if (!HeapTupleIsValid(tup))
|
2003-07-21 03:59:11 +02:00
|
|
|
elog(ERROR, "cache lookup failed for function %u", transfn);
|
2000-07-17 05:05:41 +02:00
|
|
|
proc = (Form_pg_proc) GETSTRUCT(tup);
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
/*
|
2006-07-27 21:52:07 +02:00
|
|
|
* If the transfn is strict and the initval is NULL, make sure first input
|
2006-10-04 02:30:14 +02:00
|
|
|
* type and transtype are the same (or at least binary-compatible), so
|
|
|
|
* that it's OK to use the first input value as the initial transValue.
|
2000-07-17 05:05:41 +02:00
|
|
|
*/
|
2000-11-16 23:30:52 +01:00
|
|
|
if (proc->proisstrict && agginitval == NULL)
|
2000-07-17 05:05:41 +02:00
|
|
|
{
|
2006-07-27 21:52:07 +02:00
|
|
|
if (numArgs < 1 ||
|
|
|
|
!IsBinaryCoercible(aggArgTypes[0], aggTransType))
|
2003-07-21 03:59:11 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
2003-09-25 08:58:07 +02:00
|
|
|
errmsg("must not omit initial value when transition function is strict and transition type is not compatible with input type")));
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
2000-11-16 23:30:52 +01:00
|
|
|
ReleaseSysCache(tup);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-07-17 05:05:41 +02:00
|
|
|
/* handle finalfn, if supplied */
|
1997-09-07 07:04:48 +02:00
|
|
|
if (aggfinalfnName)
|
|
|
|
{
|
2002-03-29 20:06:29 +01:00
|
|
|
fnArgs[0] = aggTransType;
|
2003-07-01 21:10:53 +02:00
|
|
|
finalfn = lookup_agg_function(aggfinalfnName, 1, fnArgs,
|
|
|
|
&finaltype);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
2000-03-26 21:43:58 +02:00
|
|
|
else
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
2000-07-17 05:05:41 +02:00
|
|
|
* If no finalfn, aggregate result type is type of the state value
|
2000-03-26 21:43:58 +02:00
|
|
|
*/
|
2002-03-29 20:06:29 +01:00
|
|
|
finaltype = aggTransType;
|
2000-03-26 21:43:58 +02:00
|
|
|
}
|
2000-07-17 05:05:41 +02:00
|
|
|
Assert(OidIsValid(finaltype));
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2003-07-01 21:10:53 +02:00
|
|
|
/*
|
2006-07-27 21:52:07 +02:00
|
|
|
* If finaltype (i.e. aggregate return type) is polymorphic, inputs must
|
2005-10-15 04:49:52 +02:00
|
|
|
* be polymorphic also, else parser will fail to deduce result type.
|
2006-07-27 21:52:07 +02:00
|
|
|
* (Note: given the previous test on transtype and inputs, this cannot
|
2005-10-15 04:49:52 +02:00
|
|
|
* happen, unless someone has snuck a finalfn definition into the catalogs
|
|
|
|
* that itself violates the rule against polymorphic result with no
|
|
|
|
* polymorphic input.)
|
2003-07-01 21:10:53 +02:00
|
|
|
*/
|
2006-07-27 21:52:07 +02:00
|
|
|
if (!hasPolyArg &&
|
|
|
|
(finaltype == ANYARRAYOID || finaltype == ANYELEMENTOID))
|
2003-07-21 03:59:11 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
2003-09-25 08:58:07 +02:00
|
|
|
errmsg("cannot determine result data type"),
|
2005-10-15 04:49:52 +02:00
|
|
|
errdetail("An aggregate returning \"anyarray\" or \"anyelement\" "
|
2006-07-27 21:52:07 +02:00
|
|
|
"must have at least one argument of either type.")));
|
2003-07-01 21:10:53 +02:00
|
|
|
|
2005-04-12 06:26:34 +02:00
|
|
|
/* handle sortop, if supplied */
|
|
|
|
if (aggsortopName)
|
2006-07-27 21:52:07 +02:00
|
|
|
{
|
|
|
|
if (numArgs != 1)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
|
|
|
errmsg("sort operator can only be specified for single-argument aggregates")));
|
2006-03-14 23:48:25 +01:00
|
|
|
sortop = LookupOperName(NULL, aggsortopName,
|
2006-07-27 21:52:07 +02:00
|
|
|
aggArgTypes[0], aggArgTypes[0],
|
2006-03-14 23:48:25 +01:00
|
|
|
false, -1);
|
2006-07-27 21:52:07 +02:00
|
|
|
}
|
2005-04-12 06:26:34 +02:00
|
|
|
|
2002-04-11 22:00:18 +02:00
|
|
|
/*
|
|
|
|
* Everything looks okay. Try to create the pg_proc entry for the
|
2005-10-15 04:49:52 +02:00
|
|
|
* aggregate. (This could fail if there's already a conflicting entry.)
|
2002-04-11 22:00:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
procOid = ProcedureCreate(aggName,
|
|
|
|
aggNamespace,
|
2002-09-04 22:31:48 +02:00
|
|
|
false, /* no replacement */
|
|
|
|
false, /* doesn't return a set */
|
|
|
|
finaltype, /* returnType */
|
|
|
|
INTERNALlanguageId, /* languageObjectId */
|
2005-04-01 00:46:33 +02:00
|
|
|
InvalidOid, /* no validator */
|
2002-09-04 22:31:48 +02:00
|
|
|
"aggregate_dummy", /* placeholder proc */
|
|
|
|
"-", /* probin */
|
|
|
|
true, /* isAgg */
|
|
|
|
false, /* security invoker (currently not
|
|
|
|
* definable for agg) */
|
|
|
|
false, /* isStrict (not needed for agg) */
|
|
|
|
PROVOLATILE_IMMUTABLE, /* volatility (not
|
|
|
|
* needed for agg) */
|
2006-07-27 21:52:07 +02:00
|
|
|
buildoidvector(aggArgTypes,
|
2006-10-04 02:30:14 +02:00
|
|
|
numArgs), /* paramTypes */
|
2005-04-01 00:46:33 +02:00
|
|
|
PointerGetDatum(NULL), /* allParamTypes */
|
|
|
|
PointerGetDatum(NULL), /* parameterModes */
|
|
|
|
PointerGetDatum(NULL)); /* parameterNames */
|
2002-04-11 22:00:18 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Okay to create the pg_aggregate entry.
|
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* initialize nulls and values */
|
|
|
|
for (i = 0; i < Natts_pg_aggregate; i++)
|
|
|
|
{
|
|
|
|
nulls[i] = ' ';
|
|
|
|
values[i] = (Datum) NULL;
|
|
|
|
}
|
2002-04-11 22:00:18 +02:00
|
|
|
values[Anum_pg_aggregate_aggfnoid - 1] = ObjectIdGetDatum(procOid);
|
2000-07-17 05:05:41 +02:00
|
|
|
values[Anum_pg_aggregate_aggtransfn - 1] = ObjectIdGetDatum(transfn);
|
|
|
|
values[Anum_pg_aggregate_aggfinalfn - 1] = ObjectIdGetDatum(finalfn);
|
2005-04-12 06:26:34 +02:00
|
|
|
values[Anum_pg_aggregate_aggsortop - 1] = ObjectIdGetDatum(sortop);
|
2002-03-29 20:06:29 +01:00
|
|
|
values[Anum_pg_aggregate_aggtranstype - 1] = ObjectIdGetDatum(aggTransType);
|
2000-07-17 05:05:41 +02:00
|
|
|
if (agginitval)
|
|
|
|
values[Anum_pg_aggregate_agginitval - 1] =
|
|
|
|
DirectFunctionCall1(textin, CStringGetDatum(agginitval));
|
1997-09-07 07:04:48 +02:00
|
|
|
else
|
2000-07-17 05:05:41 +02:00
|
|
|
nulls[Anum_pg_aggregate_agginitval - 1] = 'n';
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2005-04-14 22:03:27 +02:00
|
|
|
aggdesc = heap_open(AggregateRelationId, RowExclusiveLock);
|
1997-09-07 07:04:48 +02:00
|
|
|
tupDesc = aggdesc->rd_att;
|
2002-04-11 22:00:18 +02:00
|
|
|
|
|
|
|
tup = heap_formtuple(tupDesc, values, nulls);
|
2002-05-22 00:05:55 +02:00
|
|
|
simple_heap_insert(aggdesc, tup);
|
1999-11-22 18:56:41 +01:00
|
|
|
|
2002-08-05 05:29:17 +02:00
|
|
|
CatalogUpdateIndexes(aggdesc, tup);
|
1999-11-22 18:56:41 +01:00
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
heap_close(aggdesc, RowExclusiveLock);
|
2002-07-17 00:12:20 +02:00
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Create dependencies for the aggregate (above and beyond those already
|
|
|
|
* made by ProcedureCreate). Note: we don't need an explicit dependency
|
|
|
|
* on aggTransType since we depend on it indirectly through transfn.
|
2002-07-17 00:12:20 +02:00
|
|
|
*/
|
2005-04-14 03:38:22 +02:00
|
|
|
myself.classId = ProcedureRelationId;
|
2002-07-17 00:12:20 +02:00
|
|
|
myself.objectId = procOid;
|
|
|
|
myself.objectSubId = 0;
|
|
|
|
|
|
|
|
/* Depends on transition function */
|
2005-04-14 03:38:22 +02:00
|
|
|
referenced.classId = ProcedureRelationId;
|
2002-07-17 00:12:20 +02:00
|
|
|
referenced.objectId = transfn;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
|
|
|
|
/* Depends on final function, if any */
|
|
|
|
if (OidIsValid(finalfn))
|
|
|
|
{
|
2005-04-14 03:38:22 +02:00
|
|
|
referenced.classId = ProcedureRelationId;
|
2002-07-17 00:12:20 +02:00
|
|
|
referenced.objectId = finalfn;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
}
|
2005-04-12 06:26:34 +02:00
|
|
|
|
|
|
|
/* Depends on sort operator, if any */
|
|
|
|
if (OidIsValid(sortop))
|
|
|
|
{
|
2005-04-14 22:03:27 +02:00
|
|
|
referenced.classId = OperatorRelationId;
|
2005-04-12 06:26:34 +02:00
|
|
|
referenced.objectId = sortop;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2003-07-01 21:10:53 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* lookup_agg_function -- common code for finding both transfn and finalfn
|
|
|
|
*/
|
|
|
|
static Oid
|
|
|
|
lookup_agg_function(List *fnName,
|
|
|
|
int nargs,
|
|
|
|
Oid *input_types,
|
|
|
|
Oid *rettype)
|
|
|
|
{
|
|
|
|
Oid fnOid;
|
|
|
|
bool retset;
|
|
|
|
Oid *true_oid_array;
|
|
|
|
FuncDetailCode fdresult;
|
2005-01-28 00:42:18 +01:00
|
|
|
AclResult aclresult;
|
2006-07-27 21:52:07 +02:00
|
|
|
int i;
|
|
|
|
bool allPolyArgs = true;
|
2003-07-01 21:10:53 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* func_get_detail looks up the function in the catalogs, does
|
|
|
|
* disambiguation for polymorphic functions, handles inheritance, and
|
|
|
|
* returns the funcid and type and set or singleton status of the
|
2005-10-15 04:49:52 +02:00
|
|
|
* function's return value. it also returns the true argument types to
|
|
|
|
* the function.
|
2003-07-01 21:10:53 +02:00
|
|
|
*/
|
|
|
|
fdresult = func_get_detail(fnName, NIL, nargs, input_types,
|
|
|
|
&fnOid, rettype, &retset,
|
|
|
|
&true_oid_array);
|
|
|
|
|
|
|
|
/* only valid case is a normal function not returning a set */
|
2003-07-04 04:51:34 +02:00
|
|
|
if (fdresult != FUNCDETAIL_NORMAL || !OidIsValid(fnOid))
|
2003-07-21 03:59:11 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_UNDEFINED_FUNCTION),
|
|
|
|
errmsg("function %s does not exist",
|
2005-10-15 04:49:52 +02:00
|
|
|
func_signature_string(fnName, nargs, input_types))));
|
2003-07-04 04:51:34 +02:00
|
|
|
if (retset)
|
2003-07-21 03:59:11 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
|
|
|
errmsg("function %s returns a set",
|
2005-10-15 04:49:52 +02:00
|
|
|
func_signature_string(fnName, nargs, input_types))));
|
2003-07-01 21:10:53 +02:00
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* If the given type(s) are all polymorphic, there's nothing we can check.
|
|
|
|
* Otherwise, enforce consistency, and possibly refine the result type.
|
2003-07-01 21:10:53 +02:00
|
|
|
*/
|
2006-07-27 21:52:07 +02:00
|
|
|
for (i = 0; i < nargs; i++)
|
2003-07-01 21:10:53 +02:00
|
|
|
{
|
2006-07-27 21:52:07 +02:00
|
|
|
if (input_types[i] != ANYARRAYOID &&
|
|
|
|
input_types[i] != ANYELEMENTOID)
|
|
|
|
{
|
|
|
|
allPolyArgs = false;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-01 21:10:53 +02:00
|
|
|
}
|
2006-07-27 21:52:07 +02:00
|
|
|
|
|
|
|
if (!allPolyArgs)
|
2003-07-01 21:10:53 +02:00
|
|
|
{
|
|
|
|
*rettype = enforce_generic_type_consistency(input_types,
|
|
|
|
true_oid_array,
|
|
|
|
nargs,
|
|
|
|
*rettype);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* func_get_detail will find functions requiring run-time argument type
|
|
|
|
* coercion, but nodeAgg.c isn't prepared to deal with that
|
2003-07-01 21:10:53 +02:00
|
|
|
*/
|
2006-07-27 21:52:07 +02:00
|
|
|
for (i = 0; i < nargs; i++)
|
|
|
|
{
|
|
|
|
if (true_oid_array[i] != ANYARRAYOID &&
|
|
|
|
true_oid_array[i] != ANYELEMENTOID &&
|
|
|
|
!IsBinaryCoercible(input_types[i], true_oid_array[i]))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
|
|
|
errmsg("function %s requires run-time type coercion",
|
2006-10-04 02:30:14 +02:00
|
|
|
func_signature_string(fnName, nargs, true_oid_array))));
|
2006-07-27 21:52:07 +02:00
|
|
|
}
|
2003-07-01 21:10:53 +02:00
|
|
|
|
2005-01-28 00:42:18 +01:00
|
|
|
/* Check aggregate creator has permission to call the function */
|
|
|
|
aclresult = pg_proc_aclcheck(fnOid, GetUserId(), ACL_EXECUTE);
|
|
|
|
if (aclresult != ACLCHECK_OK)
|
|
|
|
aclcheck_error(aclresult, ACL_KIND_PROC, get_func_name(fnOid));
|
|
|
|
|
2003-07-01 21:10:53 +02:00
|
|
|
return fnOid;
|
|
|
|
}
|