...
bool is_null = true;
Datum raw_array = SPI_getbinval(heap_tuple, tuple_desc, column_of_array, &is_null);
if ( !is_null ) {
ArrayType *pg_array = DatumGetArrayTypeP(raw_array);
int array_dimensionality = ARR_NDIM(pg_array);
// Not prepared for multi-dimension array
if ( array_dimensionality == 1 ) {
double *c_array = VARDATA(pg_array); // Pointer to the array data
int array_size = ARR_DIMS(pg_array)[0]; // Element count of array at [dimension]
// Cycle through a single dimension array
for (int i = 0 ; i < array_size ; ++i) {
elog(INFO, "Double value at element %d: %lf\n", i, c_array[i]);
}
}
}
...
PSelog()
是printf()
函数的 PostgreSQL 版本(带有附加功能) - 使用它。