MCPcopy Create free account
hub / github.com/apache/madlib / array_max_index

Function array_max_index

methods/array_ops/src/pg_gp/array_ops.c:564–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

562 */
563PG_FUNCTION_INFO_V1(array_max_index);
564Datum
565array_max_index(PG_FUNCTION_ARGS) {
566 if (PG_ARGISNULL(0)) { PG_RETURN_NULL(); }
567 ArrayType *v = PG_GETARG_ARRAYTYPE_P(0);
568
569 if (ARR_NDIM(v) != 1) {
570 ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
571 errmsg("Input array with multiple dimensions is not allowed!")));
572 }
573
574 value_index *result = (value_index *)palloc(sizeof(value_index));
575 result->value = -get_float8_infinity();
576 result->index = 0;
577
578 Datum res = General_Array_to_Struct(v, result, element_argmax, value_index_finalize);
579
580 pfree(result);
581 PG_FREE_IF_COPY(v, 0);
582 return res;
583}
584
585/*
586 * This function returns minimum and corresponding index of the array elements.

Callers

nothing calls this directly

Calls 1

General_Array_to_StructFunction · 0.85

Tested by

no test coverage detected