I am having an issue with extracting data from the arguments within my ‘C’ function, inside my Stored Library.
Let’s put the pieces together first:
I have a type called rank_post which has two one character fields:
CREATE TYPE rank_post AS
(
rank character(1),
post character(1)
);
I am using the following select statement to call the stored library function.
typedef struct {
char rank;
char post;
} TdbRank;
Datum rotation(PG_FUNCTION_ARGS)
{
ArrayType *attr_arr = PG_GETARG_ARRAYTYPE_P(0);
Oid attr_element_type = ARR_ELEMTYPE(attr_arr);
int attr_ndims = ARR_NDIM(attr_arr);
int *attr_dim_counts = ARR_DIMS(attr_arr);
int *attr_dim_lower_bounds = ARR_LBOUND(attr_arr);
int ncols = attr_dim_counts[0];
int16 attr_len;
bool attr_byval;
char attr_align;
int indx[MAXDIM];
bool isNull;
TdbRank item[ncols];
Int xItem;
Datum datumResult;
get_typlenbyvalalign(attr_element_type, &attr_len, &attr_byval, &attr_align);
for(xItem = 0; xItem < ncols; xItem++) {
indx[0] = xItem + attr_dim_lower_bounds[0];
datumResult = array_ref(attr_arr, attr_ndims, indx, -1, attr_len, attr_byval, attr_align, &isNull);
????? /* how do I extract the data */
item[xItem].rank = ?;
item[xItem].post = ?;
}
...
}
After reading for an extended period of time, and trying what I thought was right, I am still at a loss on how to extract the data out. When I print the the ndims and ncols I do get the right results of 1 and 4, and when I print the hex address each datum each is 32 bytes.
I am not sure what more someone needs to help, but this is the most information I have and can release. So if you can help, it would be greatly appreciated.