* Prepare state data for a numeric aggregate function that needs to compute * sum, count and optionally sum of squares of the input. */
| 4622 | * sum, count and optionally sum of squares of the input. |
| 4623 | */ |
| 4624 | static NumericAggState * |
| 4625 | makeNumericAggState(FunctionCallInfo fcinfo, bool calcSumX2) |
| 4626 | { |
| 4627 | NumericAggState *state; |
| 4628 | MemoryContext agg_context; |
| 4629 | MemoryContext old_context; |
| 4630 | |
| 4631 | if (!AggCheckCallContext(fcinfo, &agg_context)) |
| 4632 | elog(ERROR, "aggregate function called in non-aggregate context"); |
| 4633 | |
| 4634 | old_context = MemoryContextSwitchTo(agg_context); |
| 4635 | |
| 4636 | state = (NumericAggState *) palloc0(sizeof(NumericAggState)); |
| 4637 | state->calcSumX2 = calcSumX2; |
| 4638 | state->agg_context = agg_context; |
| 4639 | init_sumaccum(&state->sumX); |
| 4640 | init_sumaccum(&state->sumX2); |
| 4641 | |
| 4642 | MemoryContextSwitchTo(old_context); |
| 4643 | |
| 4644 | return state; |
| 4645 | } |
| 4646 | |
| 4647 | /* |
| 4648 | * Like makeNumericAggState(), but allocate the state in the current memory |
no test coverage detected