i extending postgresql functions using c spi. function needs able take in postgres n-dim array , data out of it. able data 1d array segfault when trying access n-dim array.
my first try access element simply
pg_function_info_v1(sum_elements); datum matmul(pg_function_args) { arraytype *anyarray = pg_getarg_arraytype_p(0); int32 **a = (int32 **) arr_data_ptr(anyarray); pg_return_int64(a[1][1]); }
i tried if flattened matrix 1d array values came out garbage.
thanks help!
you can try using deconstruct_array (..) function extract values. function give datum type pointer.
example of book:
deconstruct_array(input_array, //one-dimensional array int4oid, //of integers 4,//size of integer in bytes true,//int4 pass-by value 'i',//alignment type 'i' &datums, &nulls, &count); // result here
"the datums pointer set point array filled actual elements."
you can access values using:
datumgetint32(datums[i]);
Comments
Post a Comment