Database Reference
In-Depth Information
Assert( ARR_ELEMTYPE(input_array) == INT4OID);
We assert that the element type of returned array is indeed an integer. (There are
some inconsistencies in PostgreSQL code as the plain integer type can be called
either int32 or int4 depending on where the definition comes from, but they both
do mean the same thing, just one is based on the length in bits and the other in
bytes.)
The type check is an assert and not plain runtime check because after you have your
SQL definition part of the function in place PostgreSQL itself takes care not to call
the function with any other type of array.
The second check is for checking that the argument is really a one-dimensional array
(PostgreSQL arrays can have 1 to n dimensions and still be of the same type).
if ( ARR_NDIM(input_array) > 1)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("use only
one-dimensional arrays!")));
If the input array has more than one dimension, we raise an error. (We will discuss
PostgreSQL's error reporting in C later in its own section).
Note
If you need to work on arrays of arbitrary number of dimensions take a look at
the source code of unnest() SQL function which turns any array into a set of
array elements.
The code is located in backend/utils/adt/arrayfuncs.c file in C function
array_unnest(...) .
Search WWH ::




Custom Search