From: | LLC Chief Financial Officer <llccfo(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Need help on extracting composite array element in ‘C’ |
Date: | 2010-06-25 18:45:55 |
Message-ID: | AANLkTinu8xPGVAJclik2yb87ReynWJByJGsfJRMJpwsq@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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.
select
rotation(array[('5','A')::rank_post,('1','Z')::rank_post,('2','S')::rank_post,('3','D')::rank_post]);
So inside my stored library function I have
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.
From | Date | Subject | |
---|---|---|---|
Next Message | Ivan Sergio Borgonovo | 2010-06-25 19:34:22 | Re: Need Some Recent Information on the Differences between Postgres and MySql |
Previous Message | Adrian Klaver | 2010-06-25 18:29:53 | Re: PG dump and restore |