* numeric_deserialize * Deserialization function for NumericAggState for numeric aggregates that * require sumX2. Deserializes bytea into into NumericAggState using the * standard pq API. * * numeric_serialize(numeric_deserialize(bytea)) must result in a value which * matches the original bytea value. */
| 5232 | * matches the original bytea value. |
| 5233 | */ |
| 5234 | Datum |
| 5235 | numeric_deserialize(PG_FUNCTION_ARGS) |
| 5236 | { |
| 5237 | bytea *sstate; |
| 5238 | NumericAggState *result; |
| 5239 | Datum temp; |
| 5240 | NumericVar sumX_var; |
| 5241 | NumericVar sumX2_var; |
| 5242 | StringInfoData buf; |
| 5243 | |
| 5244 | if (!AggCheckCallContext(fcinfo, NULL)) |
| 5245 | elog(ERROR, "aggregate function called in non-aggregate context"); |
| 5246 | |
| 5247 | sstate = PG_GETARG_BYTEA_PP(0); |
| 5248 | |
| 5249 | /* |
| 5250 | * Copy the bytea into a StringInfo so that we can "receive" it using the |
| 5251 | * standard recv-function infrastructure. |
| 5252 | */ |
| 5253 | initStringInfo(&buf); |
| 5254 | appendBinaryStringInfo(&buf, |
| 5255 | VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate)); |
| 5256 | |
| 5257 | result = makeNumericAggStateCurrentContext(false); |
| 5258 | |
| 5259 | /* N */ |
| 5260 | result->N = pq_getmsgint64(&buf); |
| 5261 | |
| 5262 | /* sumX */ |
| 5263 | temp = DirectFunctionCall3(numeric_recv, |
| 5264 | PointerGetDatum(&buf), |
| 5265 | ObjectIdGetDatum(InvalidOid), |
| 5266 | Int32GetDatum(-1)); |
| 5267 | init_var_from_num(DatumGetNumeric(temp), &sumX_var); |
| 5268 | accum_sum_add(&(result->sumX), &sumX_var); |
| 5269 | |
| 5270 | /* sumX2 */ |
| 5271 | temp = DirectFunctionCall3(numeric_recv, |
| 5272 | PointerGetDatum(&buf), |
| 5273 | ObjectIdGetDatum(InvalidOid), |
| 5274 | Int32GetDatum(-1)); |
| 5275 | init_var_from_num(DatumGetNumeric(temp), &sumX2_var); |
| 5276 | accum_sum_add(&(result->sumX2), &sumX2_var); |
| 5277 | |
| 5278 | /* maxScale */ |
| 5279 | result->maxScale = pq_getmsgint(&buf, 4); |
| 5280 | |
| 5281 | /* maxScaleCount */ |
| 5282 | result->maxScaleCount = pq_getmsgint64(&buf); |
| 5283 | |
| 5284 | /* NaNcount */ |
| 5285 | result->NaNcount = pq_getmsgint64(&buf); |
| 5286 | |
| 5287 | /* pInfcount */ |
| 5288 | result->pInfcount = pq_getmsgint64(&buf); |
| 5289 | |
| 5290 | /* nInfcount */ |
| 5291 | result->nInfcount = pq_getmsgint64(&buf); |
nothing calls this directly
no test coverage detected