Database Reference
In-Depth Information
After we have done basic sanity checking on the argument, we are ready to start
processing the array. As a PostgreSQL array can be quite a complex beast with
multiple dimensions and array element starting at arbitrary index, it is easiest to
use a ready-made utility function for most tasks. So here we use the decon-
struct_array(...) function to extract a PostgreSQL array in three separate C
variables:
Datum *datums;
bool *nulls;
int count;
The datums pointer will be set to point to an array filled with actual elements. The
*nulls will contain a pointer to an array of Booleans, which will be true if the corres-
ponding array element was NULL , and count will be set to the number of elements
found in the array.
deconstruct_array( input_array, //
one-dimensional array
INT4OID, // of
integers
4, // size of
integer in bytes
true, // int4 is
pass-by value
'i', //
alignment type is 'i'
&datums, &nulls, &count);
// result here
The other arguments are as follows:
input_array - the pointer to PostgreSQL array
INT4OID - the type of array element
element size - the true in-memory size of the
element type
Search WWH ::




Custom Search