aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/array_userfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-02-08 20:39:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-02-08 20:39:52 +0000
commitd5768dce10576c2fb1254c03fb29475d4fac6bb4 (patch)
tree7b971cb06b6671d66df26027909e1d9355d65d14 /src/backend/utils/adt/array_userfuncs.c
parent4d3d2e2b0325e3d6d524c6801b7439d3aaea4520 (diff)
downloadpostgresql-d5768dce10576c2fb1254c03fb29475d4fac6bb4.tar.gz
postgresql-d5768dce10576c2fb1254c03fb29475d4fac6bb4.zip
Create an official API function for C functions to use to check if they are
being called as aggregates, and to get the aggregate transition state memory context if needed. Use it instead of poking directly into AggState and WindowAggState in places that shouldn't know so much. We should have done this in 8.4, probably, but better late than never. Revised version of a patch by Hitoshi Harada.
Diffstat (limited to 'src/backend/utils/adt/array_userfuncs.c')
-rw-r--r--src/backend/utils/adt/array_userfuncs.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/backend/utils/adt/array_userfuncs.c b/src/backend/utils/adt/array_userfuncs.c
index 0bdb3d8a8a8..7d4ea11bf8b 100644
--- a/src/backend/utils/adt/array_userfuncs.c
+++ b/src/backend/utils/adt/array_userfuncs.c
@@ -6,13 +6,12 @@
* Copyright (c) 2003-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.33 2010/01/02 16:57:53 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.34 2010/02/08 20:39:51 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include "nodes/execnodes.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
@@ -484,15 +483,10 @@ array_agg_transfn(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not determine input data type")));
- if (fcinfo->context && IsA(fcinfo->context, AggState))
- aggcontext = ((AggState *) fcinfo->context)->aggcontext;
- else if (fcinfo->context && IsA(fcinfo->context, WindowAggState))
- aggcontext = ((WindowAggState *) fcinfo->context)->wincontext;
- else
+ if (!AggCheckCallContext(fcinfo, &aggcontext))
{
/* cannot be called directly because of internal-type argument */
elog(ERROR, "array_agg_transfn called in non-aggregate context");
- aggcontext = NULL; /* keep compiler quiet */
}
state = PG_ARGISNULL(0) ? NULL : (ArrayBuildState *) PG_GETARG_POINTER(0);
@@ -528,9 +522,7 @@ array_agg_finalfn(PG_FUNCTION_ARGS)
PG_RETURN_NULL(); /* returns null iff no input values */
/* cannot be called directly because of internal-type argument */
- Assert(fcinfo->context &&
- (IsA(fcinfo->context, AggState) ||
- IsA(fcinfo->context, WindowAggState)));
+ Assert(AggCheckCallContext(fcinfo, NULL));
state = (ArrayBuildState *) PG_GETARG_POINTER(0);