return state;
}
+/*
+ * Like makeNumericAggState(), but allocate the state in the current memory
+ * context.
+ */
+static NumericAggState *
+makeNumericAggStateCurrentContext(bool calcSumX2)
+{
+ NumericAggState *state;
+
+ state = (NumericAggState *) palloc0(sizeof(NumericAggState));
+ state->calcSumX2 = calcSumX2;
+ state->agg_context = CurrentMemoryContext;
+
+ return state;
+}
+
/*
* Accumulate a new input value for numeric aggregate functions.
*/
{
old_context = MemoryContextSwitchTo(agg_context);
- state1 = makeNumericAggState(fcinfo, true);
+ state1 = makeNumericAggStateCurrentContext(true);
state1->N = state2->N;
state1->NaNcount = state2->NaNcount;
state1->maxScale = state2->maxScale;
{
old_context = MemoryContextSwitchTo(agg_context);
- state1 = makeNumericAggState(fcinfo, false);
+ state1 = makeNumericAggStateCurrentContext(false);
state1->N = state2->N;
state1->NaNcount = state2->NaNcount;
state1->maxScale = state2->maxScale;
/*
* Copy the bytea into a StringInfo so that we can "receive" it using the
- * standard pq API.
+ * standard recv-function infrastructure.
*/
initStringInfo(&buf);
appendBinaryStringInfo(&buf, VARDATA(sstate), VARSIZE(sstate) - VARHDRSZ);
- result = makeNumericAggState(fcinfo, false);
+ result = makeNumericAggStateCurrentContext(false);
/* N */
result->N = pq_getmsgint64(&buf);
/*
* Copy the bytea into a StringInfo so that we can "receive" it using the
- * standard pq API.
+ * standard recv-function infrastructure.
*/
initStringInfo(&buf);
appendBinaryStringInfo(&buf, VARDATA(sstate), VARSIZE(sstate) - VARHDRSZ);
- result = makeNumericAggState(fcinfo, false);
+ result = makeNumericAggStateCurrentContext(false);
/* N */
result->N = pq_getmsgint64(&buf);
return state;
}
+/*
+ * Like makeInt128AggState(), but allocate the state in the current memory
+ * context.
+ */
+static Int128AggState *
+makeInt128AggStateCurrentContext(bool calcSumX2)
+{
+ Int128AggState *state;
+
+ state = (Int128AggState *) palloc0(sizeof(Int128AggState));
+ state->calcSumX2 = calcSumX2;
+
+ return state;
+}
+
/*
* Accumulate a new input value for 128-bit aggregate functions.
*/
typedef Int128AggState PolyNumAggState;
#define makePolyNumAggState makeInt128AggState
+#define makePolyNumAggStateCurrentContext makeInt128AggStateCurrentContext
#else
typedef NumericAggState PolyNumAggState;
#define makePolyNumAggState makeNumericAggState
+#define makePolyNumAggStateCurrentContext makeNumericAggStateCurrentContext
#endif
Datum
/*
* Copy the bytea into a StringInfo so that we can "receive" it using the
- * standard pq API.
+ * standard recv-function infrastructure.
*/
initStringInfo(&buf);
appendBinaryStringInfo(&buf, VARDATA(sstate), VARSIZE(sstate) - VARHDRSZ);
- result = makePolyNumAggState(fcinfo, false);
+ result = makePolyNumAggStateCurrentContext(false);
/* N */
result->N = pq_getmsgint64(&buf);
/*
* int8_avg_serialize
- * Serialize PolyNumAggState into bytea using the standard pq API.
+ * Serialize PolyNumAggState into bytea using the standard
+ * recv-function infrastructure.
*/
Datum
int8_avg_serialize(PG_FUNCTION_ARGS)
/*
* Copy the bytea into a StringInfo so that we can "receive" it using the
- * standard pq API.
+ * standard recv-function infrastructure.
*/
initStringInfo(&buf);
appendBinaryStringInfo(&buf, VARDATA(sstate), VARSIZE(sstate) - VARHDRSZ);
- result = makePolyNumAggState(fcinfo, false);
+ result = makePolyNumAggStateCurrentContext(false);
/* N */
result->N = pq_getmsgint64(&buf);