From d5768dce10576c2fb1254c03fb29475d4fac6bb4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 8 Feb 2010 20:39:52 +0000 Subject: 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. --- src/backend/utils/adt/array_userfuncs.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src/backend/utils/adt/array_userfuncs.c') 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); -- cgit v1.2.3