28 #include <utils/lsyscache.h>
29 #include <catalog/pg_type.h>
55 clock_t start_t = clock();
56 int64_t *c_array = NULL;
58 Oid element_type = ARR_ELEMTYPE(v);
59 int *dim = ARR_DIMS(v);
60 int ndim = ARR_NDIM(v);
61 int nitems = ArrayGetNItems(ndim, dim);
68 assert((*arrlen) == 0);
71 if (allow_empty && (ndim == 0 || nitems <= 0)) {
72 PGR_DBG(
"ndim %i nitems % i", ndim, nitems);
73 return (int64_t*)NULL;
78 elog(ERROR,
"One dimension expected");
79 return (int64_t*)NULL;
83 elog(ERROR,
"No elements found");
84 return (int64_t*)NULL;
87 get_typlenbyvalalign(element_type,
88 &typlen, &typbyval, &typalign);
91 switch (element_type) {
97 elog(ERROR,
"Expected array of ANY-INTEGER");
98 return (int64_t*)NULL;
102 deconstruct_array(v, element_type, typlen, typbyval,
103 typalign, &elements, &nulls,
106 c_array = (int64_t *) palloc(
sizeof(int64_t) * (size_t)nitems);
108 elog(ERROR,
"Out of memory!");
113 for (i = 0; i < nitems; i++) {
116 elog(ERROR,
"NULL value found in Array!");
118 switch (element_type) {
120 c_array[i] = (int64_t) DatumGetInt16(elements[i]);
123 c_array[i] = (int64_t) DatumGetInt32(elements[i]);
126 c_array[i] = DatumGetInt64(elements[i]);
131 (*arrlen) = (size_t)nitems;
135 PGR_DBG(
"Array size %ld", (*arrlen));
136 time_msg(
"reading Array", start_t, clock());