32 #include <utils/lsyscache.h>
33 #include <catalog/pg_type.h>
44 clock_t start_t = clock();
47 int64_t *c_array = NULL;
49 Oid element_type = ARR_ELEMTYPE(v);
50 int *dim = ARR_DIMS(v);
51 int ndim = ARR_NDIM(v);
52 int nitems = ArrayGetNItems(ndim, dim);
59 assert((*arrlen) == 0);
62 if (allow_empty && (ndim == 0 || nitems <= 0)) {
63 return (int64_t*) NULL;
68 elog(ERROR,
"One dimension expected");
72 elog(ERROR,
"No elements found");
75 get_typlenbyvalalign(element_type,
76 &typlen, &typbyval, &typalign);
79 switch (element_type) {
85 elog(ERROR,
"Expected array of ANY-INTEGER");
88 deconstruct_array(v, element_type, typlen, typbyval,
89 typalign, &elements, &nulls,
92 c_array = (int64_t *) palloc(
sizeof(int64_t) * (size_t)nitems);
94 elog(ERROR,
"Out of memory!");
99 for (i = 0; i < nitems; i++) {
102 elog(ERROR,
"NULL value found in Array!");
104 switch (element_type) {
106 c_array[i] = (int64_t) DatumGetInt16(elements[i]);
109 c_array[i] = (int64_t) DatumGetInt32(elements[i]);
112 c_array[i] = DatumGetInt64(elements[i]);
117 (*arrlen) = (size_t)nitems;
122 time_msg(
"reading Array", start_t, clock());
132 clock_t start_t = clock();
135 uint32_t *c_array = NULL;
137 Oid element_type = ARR_ELEMTYPE(v);
138 int *dim = ARR_DIMS(v);
139 int ndim = ARR_NDIM(v);
140 int nitems = ArrayGetNItems(ndim, dim);
147 assert((*arrlen) == 0);
150 if (allow_empty && (ndim == 0 || nitems <= 0)) {
151 return (uint32_t*) NULL;
156 elog(ERROR,
"One dimension expected");
160 elog(ERROR,
"No elements found");
163 get_typlenbyvalalign(element_type,
164 &typlen, &typbyval, &typalign);
167 switch (element_type) {
172 elog(ERROR,
"Expected array of INTEGER");
175 deconstruct_array(v, element_type, typlen, typbyval,
176 typalign, &elements, &nulls,
179 c_array = (uint32_t *) palloc(
sizeof(uint32_t) * (size_t)nitems);
181 elog(ERROR,
"Out of memory!");
186 for (i = 0; i < nitems; i++) {
189 elog(ERROR,
"NULL value found in Array!");
192 switch (element_type) {
194 element = (int32_t) DatumGetInt16(elements[i]);
197 element = (int32_t) DatumGetInt32(elements[i]);
201 elog(ERROR,
"Unexpected Negative value %d in array", element);
203 c_array[i] = (uint32_t) element;
206 (*arrlen) = (size_t)nitems;
211 time_msg(
"reading Array", start_t, clock());