Database Reference
In-Depth Information
if ( nulls[i] )
continue;
// accumulate and remember there were
non-null values
sum +=
DatumGetInt32(
datums[i]);
not_null = true;
}
if (not_null)
PG_RETURN_INT32(sum);
PG_RETURN_NULL();
}
So what new things are needed for handling array types as arguments? First, you
need to include definitions for array utility functions.
#include "utils/array.h"
Next, you need a pointer to your array.
ArrayType *
input_array;
Notice that there is no specific array-of-integers type but just a generic
ArrayType
,
which is used for any array.
To initialize the array from the first argument you use an already familiar looking
macro.
input_array = PG_GETARG_ARRAYTYPE_P(0);
Except that instead of returning a
INT32
value it returns an array pointer
ARRAYTYPE_P
.
After getting the array pointer, we perform a couple of checks.