46 #define AARR_FREE_IF_COPY(array,n) \
48 if (!VARATT_IS_EXPANDED_HEADER(array)) \
49 PG_FREE_IF_COPY(array, n); \
90 static int ArrayCount(
const char *str,
int *dim,
char typdelim);
91 static void ReadArrayStr(
char *arrayStr,
const char *origStr,
92 int nitems,
int ndim,
int *dim,
95 int typlen,
bool typbyval,
char typalign,
97 bool *hasnulls,
int32 *nbytes);
100 int typlen,
bool typbyval,
char typalign,
102 bool *hasnulls,
int32 *nbytes);
104 int nSubscripts,
int *indx,
106 int elmlen,
bool elmbyval,
char elmalign,
109 int nSubscripts,
int *indx,
110 Datum dataValue,
bool isNull,
112 int elmlen,
bool elmbyval,
char elmalign);
117 int typlen,
bool typbyval,
char typalign,
119 static char *
array_seek(
char *ptr,
int offset,
bits8 *nullbitmap,
int nitems,
120 int typlen,
bool typbyval,
char typalign);
122 int nitems,
int typlen,
bool typbyval,
char typalign);
123 static int array_copy(
char *destptr,
int nitems,
124 char *srcptr,
int offset,
bits8 *nullbitmap,
125 int typlen,
bool typbyval,
char typalign);
127 int ndim,
int *dim,
int *lb,
129 int typlen,
bool typbyval,
char typalign);
131 int ndim,
int *dim,
int *lb,
132 char *arraydataptr,
bits8 *arraynullsptr,
134 int typlen,
bool typbyval,
char typalign);
137 int ndim,
int *dim,
int *lb,
139 int typlen,
bool typbyval,
char typalign);
142 Oid elmtype,
int dataoffset);
147 Datum search,
bool search_isnull,
148 Datum replace,
bool replace_isnull,
149 bool remove,
Oid collation,
203 if (my_extra ==
NULL)
224 typlen = my_extra->
typlen;
259 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
260 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
263 for (q = p; isdigit((
unsigned char) *q) || (*q ==
'-') || (*q ==
'+'); q++)
267 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
268 errmsg(
"malformed array literal: \"%s\"",
string),
269 errdetail(
"\"[\" must introduce explicitly-specified array dimensions.")));
275 lBound[ndim] = atoi(p);
277 for (q = p; isdigit((
unsigned char) *q) || (*q ==
'-') || (*q ==
'+'); q++)
281 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
282 errmsg(
"malformed array literal: \"%s\"",
string),
283 errdetail(
"Missing array dimension value.")));
292 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
293 errmsg(
"malformed array literal: \"%s\"",
string),
294 errdetail(
"Missing \"%s\" after array dimensions.",
300 if (ub < lBound[ndim])
302 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
303 errmsg(
"upper bound cannot be less than lower bound")));
305 dim[ndim] = ub - lBound[ndim] + 1;
314 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
315 errmsg(
"malformed array literal: \"%s\"",
string),
316 errdetail(
"Array value must start with \"{\" or dimension information.")));
318 for (i = 0; i < ndim; i++)
329 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
330 errmsg(
"malformed array literal: \"%s\"",
string),
331 errdetail(
"Missing \"%s\" after array dimensions.",
343 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
344 errmsg(
"malformed array literal: \"%s\"",
string),
345 errdetail(
"Array contents must start with \"{\".")));
346 ndim_braces =
ArrayCount(p, dim_braces, typdelim);
347 if (ndim_braces != ndim)
349 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
350 errmsg(
"malformed array literal: \"%s\"",
string),
351 errdetail(
"Specified array dimensions do not match array contents.")));
352 for (i = 0; i < ndim; ++
i)
354 if (dim[i] != dim_braces[i])
356 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
357 errmsg(
"malformed array literal: \"%s\"",
string),
358 errdetail(
"Specified array dimensions do not match array contents.")));
363 printf(
"array_in- ndim %d (", ndim);
364 for (i = 0; i < ndim; i++)
366 printf(
" %d", dim[i]);
368 printf(
") for %s\n",
string);
378 nullsPtr = (
bool *)
palloc(nitems *
sizeof(
bool));
381 &my_extra->
proc, typioparam, typmod,
383 typlen, typbyval, typalign,
389 nbytes += dataoffset;
407 memcpy(
ARR_DIMS(retval), dim, ndim *
sizeof(
int));
408 memcpy(
ARR_LBOUND(retval), lBound, ndim *
sizeof(
int));
411 dataPtr, nullsPtr, nitems,
412 typlen, typbyval, typalign,
459 bool in_quotes =
false;
460 bool eoArray =
false;
461 bool empty_array =
true;
467 temp[
i] = dim[
i] = nelems_last[
i] = 0;
474 bool itemdone =
false;
487 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
488 errmsg(
"malformed array literal: \"%s\"", str),
503 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
504 errmsg(
"malformed array literal: \"%s\"", str),
505 errdetail(
"Unexpected \"%c\" character.",
514 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
515 errmsg(
"malformed array literal: \"%s\"", str),
529 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
530 errmsg(
"malformed array literal: \"%s\"", str),
531 errdetail(
"Unexpected array element.")));
532 in_quotes = !in_quotes;
550 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
551 errmsg(
"malformed array literal: \"%s\"", str),
552 errdetail(
"Unexpected \"%c\" character.",
555 if (nest_level >= MAXDIM)
557 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
558 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
559 nest_level + 1, MAXDIM)));
560 temp[nest_level] = 0;
562 if (ndim < nest_level)
580 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
581 errmsg(
"malformed array literal: \"%s\"", str),
582 errdetail(
"Unexpected \"%c\" character.",
587 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
588 errmsg(
"malformed array literal: \"%s\"", str),
589 errdetail(
"Unmatched \"%c\" character.",
'}')));
592 if (nelems_last[nest_level] != 0 &&
593 nelems[nest_level] != nelems_last[nest_level])
595 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
596 errmsg(
"malformed array literal: \"%s\"", str),
597 errdetail(
"Multidimensional arrays must have "
598 "sub-arrays with matching "
600 nelems_last[nest_level] = nelems[nest_level];
601 nelems[nest_level] = 1;
603 eoArray = itemdone =
true;
610 temp[nest_level - 1]++;
617 if (*ptr == typdelim)
629 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
630 errmsg(
"malformed array literal: \"%s\"", str),
631 errdetail(
"Unexpected \"%c\" character.",
638 nelems[nest_level - 1]++;
652 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
653 errmsg(
"malformed array literal: \"%s\"", str),
654 errdetail(
"Unexpected array element.")));
672 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
673 errmsg(
"malformed array literal: \"%s\"", str),
674 errdetail(
"Junk after closing right brace.")));
681 for (
i = 0;
i < ndim; ++
i)
736 bool in_quotes =
false;
737 bool eoArray =
false;
744 MemSet(indx, 0,
sizeof(indx));
747 memset(nulls,
true, nitems *
sizeof(
bool));
767 bool itemdone =
false;
768 bool leadingspace =
true;
769 bool hasquoting =
false;
775 itemstart = dstptr = dstendptr = srcptr;
784 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
785 errmsg(
"malformed array literal: \"%s\"",
793 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
794 errmsg(
"malformed array literal: \"%s\"",
796 *dstptr++ = *srcptr++;
798 leadingspace =
false;
803 in_quotes = !in_quotes;
805 leadingspace =
false;
821 if (nest_level >= ndim)
823 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
824 errmsg(
"malformed array literal: \"%s\"",
827 indx[nest_level - 1] = 0;
831 *dstptr++ = *srcptr++;
838 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
839 errmsg(
"malformed array literal: \"%s\"",
843 indx[nest_level - 1] = 0;
846 eoArray = itemdone =
true;
848 indx[nest_level - 1]++;
852 *dstptr++ = *srcptr++;
856 *dstptr++ = *srcptr++;
857 else if (*srcptr == typdelim)
874 *dstptr++ = *srcptr++;
878 *dstptr++ = *srcptr++;
879 leadingspace =
false;
889 if (i < 0 || i >= nitems)
891 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
892 errmsg(
"malformed array literal: \"%s\"",
916 for (i = 0; i < nitems; i++)
930 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
931 errmsg(
"array size exceeds the maximum allowed (%d)",
974 for (i = 0; i < nitems; i++)
976 if (nulls && nulls[i])
979 elog(
ERROR,
"null array element where not supported");
992 if (bitmask == 0x100)
1001 if (bitmap && bitmask != 1)
1023 dims_str[(
MAXDIM * 33) + 2];
1050 if (my_extra ==
NULL)
1071 typlen = my_extra->
typlen;
1091 for (i = 0; i < ndim; i++)
1105 values = (
char **)
palloc(nitems *
sizeof(
char *));
1106 needquotes = (
bool *)
palloc(nitems *
sizeof(
bool));
1111 for (i = 0; i < nitems; i++)
1119 typlen, typbyval, typalign);
1124 overall_length += 4;
1132 if (values[i][0] ==
'\0')
1139 for (tmp = values[i]; *tmp !=
'\0'; tmp++)
1143 overall_length += 1;
1144 if (ch ==
'"' || ch ==
'\\')
1147 overall_length += 1;
1149 else if (ch ==
'{' || ch ==
'}' || ch == typdelim ||
1155 needquotes[
i] = needquote;
1159 overall_length += 2;
1161 overall_length += 1;
1167 for (i = j = 0, k = 1; i < ndim; i++)
1168 k *= dims[i], j += k;
1175 char *ptr = dims_str;
1177 for (i = 0; i < ndim; i++)
1179 sprintf(ptr,
"[%d:%d]", lb[i], lb[i] + dims[i] - 1);
1186 retval = (
char *)
palloc(strlen(dims_str) + overall_length + 2 * j);
1189 #define APPENDSTR(str) (strcpy(p, (str)), p += strlen(p))
1190 #define APPENDCHAR(ch) (*p++ = (ch), *p = '\0')
1195 for (i = 0; i < ndim; i++)
1201 for (i = j; i < ndim - 1; i++)
1207 for (tmp = values[k]; *tmp; tmp++)
1211 if (ch ==
'"' || ch ==
'\\')
1222 for (i = ndim - 1; i >= 0; i--)
1224 indx[
i] = (indx[
i] + 1) % dims[i];
1283 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1284 errmsg(
"invalid number of dimensions: %d", ndim)));
1287 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1288 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
1292 if (flags != 0 && flags != 1)
1294 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1295 errmsg(
"invalid array flags")));
1298 if (element_type != spec_element_type)
1302 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1303 errmsg(
"wrong element type")));
1306 for (i = 0; i < ndim; i++)
1317 int ub = lBound[
i] + dim[
i] - 1;
1321 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1322 errmsg(
"integer out of range")));
1335 if (my_extra ==
NULL)
1352 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1353 errmsg(
"no binary input function available for type %s",
1366 typlen = my_extra->
typlen;
1372 nullsPtr = (
bool *)
palloc(nitems *
sizeof(
bool));
1374 &my_extra->
proc, typioparam, typmod,
1375 typlen, typbyval, typalign,
1377 &hasnulls, &nbytes);
1381 nbytes += dataoffset;
1390 retval->
ndim = ndim;
1393 memcpy(
ARR_DIMS(retval), dim, ndim *
sizeof(
int));
1394 memcpy(
ARR_LBOUND(retval), lBound, ndim *
sizeof(
int));
1397 dataPtr, nullsPtr, nitems,
1398 typlen, typbyval, typalign,
1446 for (i = 0; i < nitems; i++)
1454 if (itemlen < -1 || itemlen > (buf->
len - buf->
cursor))
1456 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1457 errmsg(
"insufficient data left in message")));
1463 typioparam, typmod);
1475 elem_buf.
maxlen = itemlen + 1;
1476 elem_buf.
len = itemlen;
1486 typioparam, typmod);
1490 if (elem_buf.
cursor != itemlen)
1492 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1493 errmsg(
"improper binary format in array element %d",
1504 for (i = 0; i < nitems; i++)
1518 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1519 errmsg(
"array size exceeds the maximum allowed (%d)",
1523 *hasnulls = hasnull;
1556 if (my_extra ==
NULL)
1573 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1574 errmsg(
"no binary output function available for type %s",
1580 typlen = my_extra->
typlen;
1595 for (i = 0; i < ndim; i++)
1604 for (i = 0; i < nitems; i++)
1611 typlen, typbyval, typalign);
1679 sprintf(p,
"[%d:%d]", lb[i], dimv[i] + lb[i] - 1);
1704 if (reqdim <= 0 || reqdim >
AARR_NDIM(v))
1708 result = lb[reqdim - 1];
1732 if (reqdim <= 0 || reqdim >
AARR_NDIM(v))
1738 result = dimv[reqdim - 1] + lb[reqdim - 1] - 1;
1761 if (reqdim <= 0 || reqdim >
AARR_NDIM(v))
1766 result = dimv[reqdim - 1];
1824 bits8 *arraynullsptr;
1826 if (arraytyplen > 0)
1832 fixedDim[0] = arraytyplen / elmlen;
1837 arraynullsptr =
NULL;
1866 if (ndim != nSubscripts || ndim <= 0 || ndim >
MAXDIM)
1871 for (i = 0; i < ndim; i++)
1873 if (indx[i] < lb[i] || indx[i] >= (dim[i] + lb[i]))
1898 retptr =
array_seek(arraydataptr, 0, arraynullsptr, offset,
1899 elmlen, elmbyval, elmalign);
1900 return ArrayCast(retptr, elmbyval, elmlen);
1908 int nSubscripts,
int *indx,
1910 int elmlen,
bool elmbyval,
char elmalign,
1926 Assert(arraytyplen == -1);
1938 if (ndim != nSubscripts || ndim <= 0 || ndim >
MAXDIM)
1943 for (i = 0; i < ndim; i++)
1945 if (indx[i] < lb[i] || indx[i] >= (dim[i] + lb[i]))
1969 if (dnulls && dnulls[offset])
1982 return dvalues[offset];
2030 bits8 *arraynullsptr;
2035 if (arraytyplen > 0)
2044 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2045 errmsg(
"slices of fixed-length arrays not implemented")));
2053 fixedDim[0] = arraytyplen / elmlen;
2059 arraynullsptr =
NULL;
2079 if (ndim < nSubscripts || ndim <= 0 || ndim >
MAXDIM)
2082 for (i = 0; i < nSubscripts; i++)
2084 if (lowerIndx[i] < lb[i])
2085 lowerIndx[
i] = lb[
i];
2086 if (upperIndx[i] >= (dim[i] + lb[i]))
2087 upperIndx[
i] = dim[
i] + lb[
i] - 1;
2088 if (lowerIndx[i] > upperIndx[i])
2092 for (; i < ndim; i++)
2094 lowerIndx[
i] = lb[
i];
2095 upperIndx[
i] = dim[
i] + lb[
i] - 1;
2096 if (lowerIndx[i] > upperIndx[i])
2104 lowerIndx, upperIndx,
2105 elmlen, elmbyval, elmalign);
2114 bytes += dataoffset;
2124 newarray->
ndim = ndim;
2127 memcpy(
ARR_DIMS(newarray), span, ndim *
sizeof(
int));
2134 for (i = 0; i < ndim; i++)
2139 arraydataptr, arraynullsptr,
2140 lowerIndx, upperIndx,
2141 elmlen, elmbyval, elmalign);
2198 bits8 *oldnullbitmap;
2212 if (arraytyplen > 0)
2220 if (nSubscripts != 1)
2222 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2223 errmsg(
"wrong number of array subscripts")));
2225 if (indx[0] < 0 || indx[0] * elmlen >= arraytyplen)
2227 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2228 errmsg(
"array subscript out of range")));
2232 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2233 errmsg(
"cannot assign null value to an element of a fixed-length array")));
2235 resultarray = (
char *)
palloc(arraytyplen);
2237 elt_ptr = (
char *) resultarray + indx[0] * elmlen;
2242 if (nSubscripts <= 0 || nSubscripts >
MAXDIM)
2244 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2245 errmsg(
"wrong number of array subscripts")));
2248 if (elmlen == -1 && !isNull)
2279 for (i = 0; i < nSubscripts; i++)
2286 nSubscripts, dim, lb,
2288 elmlen, elmbyval, elmalign));
2291 if (ndim != nSubscripts)
2293 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2294 errmsg(
"wrong number of array subscripts")));
2297 memcpy(dim,
ARR_DIMS(array), ndim *
sizeof(
int));
2298 memcpy(lb,
ARR_LBOUND(array), ndim *
sizeof(
int));
2301 addedbefore = addedafter = 0;
2308 if (indx[0] < lb[0])
2310 addedbefore = lb[0] - indx[0];
2311 dim[0] += addedbefore;
2313 if (addedbefore > 1)
2316 if (indx[0] >= (dim[0] + lb[0]))
2318 addedafter = indx[0] - (dim[0] + lb[0]) + 1;
2319 dim[0] += addedafter;
2330 for (i = 0; i < ndim; i++)
2332 if (indx[i] < lb[i] ||
2333 indx[i] >= (dim[i] + lb[i]))
2335 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2336 errmsg(
"array subscript out of range")));
2351 olddatasize =
ARR_SIZE(array) - oldoverheadlen;
2357 lenafter = olddatasize;
2359 else if (addedafter)
2362 lenbefore = olddatasize;
2370 elmlen, elmbyval, elmalign);
2379 lenafter = (int) (olddatasize - lenbefore - olditemlen);
2390 newsize = overheadlen + lenbefore + newitemlen + lenafter;
2397 newarray->
ndim = ndim;
2398 newarray->
dataoffset = newhasnulls ? overheadlen : 0;
2400 memcpy(
ARR_DIMS(newarray), dim, ndim *
sizeof(
int));
2401 memcpy(
ARR_LBOUND(newarray), lb, ndim *
sizeof(
int));
2406 memcpy((
char *) newarray + overheadlen,
2407 (
char *) array + oldoverheadlen,
2411 (
char *) newarray + overheadlen + lenbefore);
2412 memcpy((
char *) newarray + overheadlen + lenbefore + newitemlen,
2413 (
char *) array + oldoverheadlen + lenbefore + olditemlen,
2427 MemSet(newnullbitmap, 0, (newnitems + 7) / 8);
2443 if (addedafter == 0)
2445 oldnullbitmap, offset + 1,
2446 oldnitems - offset - 1);
2462 int nSubscripts,
int *indx,
2463 Datum dataValue,
bool isNull,
2465 int elmlen,
bool elmbyval,
char elmalign)
2485 Assert(arraytyplen == -1);
2497 memcpy(dim, eah->
dims, ndim *
sizeof(
int));
2498 memcpy(lb, eah->
lbound, ndim *
sizeof(
int));
2499 dimschanged =
false;
2514 nSubscripts *
sizeof(
int));
2516 nSubscripts *
sizeof(
int));
2520 for (i = 0; i < nSubscripts; i++)
2527 else if (ndim != nSubscripts)
2529 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2530 errmsg(
"wrong number of array subscripts")));
2556 newhasnulls = ((dnulls !=
NULL) || isNull);
2557 addedbefore = addedafter = 0;
2564 if (indx[0] < lb[0])
2566 addedbefore = lb[0] - indx[0];
2567 dim[0] += addedbefore;
2570 if (addedbefore > 1)
2573 if (indx[0] >= (dim[0] + lb[0]))
2575 addedafter = indx[0] - (dim[0] + lb[0]) + 1;
2576 dim[0] += addedafter;
2588 for (i = 0; i < ndim; i++)
2590 if (indx[i] < lb[i] ||
2591 indx[i] >= (dim[i] + lb[i]))
2593 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2594 errmsg(
"array subscript out of range")));
2605 int newlen = dim[0] + dim[0] / 8;
2607 newlen =
Max(newlen, dim[0]);
2611 eah->
dnulls = dnulls = (
bool *)
2612 repalloc(dnulls, newlen *
sizeof(
bool));
2620 if (newhasnulls && dnulls ==
NULL)
2621 eah->
dnulls = dnulls = (
bool *)
2639 memcpy(eah->
dims, dim, ndim *
sizeof(
int));
2640 memcpy(eah->
lbound, lb, ndim *
sizeof(
int));
2644 if (addedbefore > 0)
2647 for (i = 0; i < addedbefore; i++)
2648 dvalues[i] = (
Datum) 0;
2651 memmove(dnulls + addedbefore, dnulls, eah->
nelems *
sizeof(
bool));
2652 for (i = 0; i < addedbefore; i++)
2655 eah->
nelems += addedbefore;
2661 for (i = 0; i < addedafter; i++)
2665 for (i = 0; i < addedafter; i++)
2666 dnulls[eah->
nelems + i] =
true;
2668 eah->
nelems += addedafter;
2672 if (!eah->
typbyval && (dnulls ==
NULL || !dnulls[offset]))
2678 dvalues[offset] = dataValue;
2680 dnulls[offset] = isNull;
2690 if (oldValue < eah->fstartptr || oldValue >= eah->
fendptr)
2738 Datum srcArrayDatum,
2774 if (arraytyplen > 0)
2780 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2781 errmsg(
"updates on slices of fixed-length arrays not implemented")));
2805 &dvalues, &dnulls, &nelems);
2807 for (i = 0; i < nSubscripts; i++)
2809 dim[
i] = 1 + upperIndx[
i] - lowerIndx[
i];
2810 lb[
i] = lowerIndx[
i];
2816 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2817 errmsg(
"source array too small")));
2821 elmlen, elmbyval, elmalign));
2824 if (ndim < nSubscripts || ndim <= 0 || ndim >
MAXDIM)
2826 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2827 errmsg(
"wrong number of array subscripts")));
2830 memcpy(dim,
ARR_DIMS(array), ndim *
sizeof(
int));
2831 memcpy(lb,
ARR_LBOUND(array), ndim *
sizeof(
int));
2834 addedbefore = addedafter = 0;
2841 Assert(nSubscripts == 1);
2842 if (lowerIndx[0] > upperIndx[0])
2844 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2845 errmsg(
"upper bound cannot be less than lower bound")));
2846 if (lowerIndx[0] < lb[0])
2848 if (upperIndx[0] < lb[0] - 1)
2850 addedbefore = lb[0] - lowerIndx[0];
2851 dim[0] += addedbefore;
2852 lb[0] = lowerIndx[0];
2854 if (upperIndx[0] >= (dim[0] + lb[0]))
2856 if (lowerIndx[0] > (dim[0] + lb[0]))
2858 addedafter = upperIndx[0] - (dim[0] + lb[0]) + 1;
2859 dim[0] += addedafter;
2868 for (i = 0; i < nSubscripts; i++)
2870 if (lowerIndx[i] > upperIndx[i])
2872 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2873 errmsg(
"upper bound cannot be less than lower bound")));
2874 if (lowerIndx[i] < lb[i] ||
2875 upperIndx[i] >= (dim[i] + lb[i]))
2877 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2878 errmsg(
"array subscript out of range")));
2881 for (; i < ndim; i++)
2883 lowerIndx[
i] = lb[
i];
2884 upperIndx[
i] = dim[
i] + lb[
i] - 1;
2885 if (lowerIndx[i] > upperIndx[i])
2887 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2888 errmsg(
"upper bound cannot be less than lower bound")));
2903 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2904 errmsg(
"source array too small")));
2916 elmlen, elmbyval, elmalign);
2918 olddatasize =
ARR_SIZE(array) - oldoverheadlen;
2928 lowerIndx, upperIndx,
2929 elmlen, elmbyval, elmalign);
2930 lenbefore = lenafter = 0;
2931 itemsbefore = itemsafter = nolditems = 0;
2940 int oldub = oldlb +
ARR_DIMS(array)[0] - 1;
2941 int slicelb =
Max(oldlb, lowerIndx[0]);
2942 int sliceub =
Min(oldub, upperIndx[0]);
2947 itemsbefore =
Min(slicelb, oldub + 1) - oldlb;
2950 elmlen, elmbyval, elmalign);
2952 if (slicelb > sliceub)
2959 nolditems = sliceub - slicelb + 1;
2961 itemsbefore, oldarraybitmap,
2963 elmlen, elmbyval, elmalign);
2966 itemsafter = oldub + 1 -
Max(sliceub + 1, oldlb);
2967 lenafter = olddatasize - lenbefore - olditemsize;
2970 newsize = overheadlen + olddatasize - olditemsize + newitemsize;
2974 newarray->
ndim = ndim;
2975 newarray->
dataoffset = newhasnulls ? overheadlen : 0;
2977 memcpy(
ARR_DIMS(newarray), dim, ndim *
sizeof(
int));
2978 memcpy(
ARR_LBOUND(newarray), lb, ndim *
sizeof(
int));
2988 lowerIndx, upperIndx,
2989 elmlen, elmbyval, elmalign);
2994 memcpy((
char *) newarray + overheadlen,
2995 (
char *) array + oldoverheadlen,
2997 memcpy((
char *) newarray + overheadlen + lenbefore,
3000 memcpy((
char *) newarray + overheadlen + lenbefore + newitemsize,
3001 (
char *) array + oldoverheadlen + lenbefore + olditemsize,
3010 MemSet(newnullbitmap, 0, (nitems + 7) / 8);
3018 oldnullbitmap, itemsbefore + nolditems,
3035 int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign,
3039 arraytyplen, elmlen, elmbyval, elmalign,
3052 Datum dataValue,
bool isNull,
3053 int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign)
3059 elmlen, elmbyval, elmalign));
3116 if (fcinfo->
nargs < 1)
3150 inp_typlen = inp_extra->
typlen;
3151 inp_typbyval = inp_extra->
typbyval;
3152 inp_typalign = inp_extra->
typalign;
3162 typlen = ret_extra->
typlen;
3168 nulls = (
bool *)
palloc(nitems *
sizeof(
bool));
3174 for (i = 0; i < nitems; i++)
3180 inp_typlen, inp_typbyval, inp_typalign);
3189 for (j = 0; j < fcinfo->
nargs; j++)
3221 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3222 errmsg(
"array size exceeds the maximum allowed (%d)",
3231 nbytes += dataoffset;
3240 result->
ndim = ndim;
3250 values, nulls, nitems,
3251 typlen, typbyval, typalign,
3279 int elmlen,
bool elmbyval,
char elmalign)
3288 elmtype, elmlen, elmbyval, elmalign);
3316 Oid elmtype,
int elmlen,
bool elmbyval,
char elmalign)
3327 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3328 errmsg(
"invalid number of dimensions: %d", ndims)));
3331 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3332 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
3344 for (i = 0; i < nelems; i++)
3346 if (nulls && nulls[i])
3359 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3360 errmsg(
"array size exceeds the maximum allowed (%d)",
3368 nbytes += dataoffset;
3377 result->
ndim = ndims;
3380 memcpy(
ARR_DIMS(result), dims, ndims *
sizeof(
int));
3381 memcpy(
ARR_LBOUND(result), lbs, ndims *
sizeof(
int));
3384 elems, nulls, nelems,
3385 elmlen, elmbyval, elmalign,
3448 int elmlen,
bool elmbyval,
char elmalign,
3449 Datum **elemsp,
bool **nullsp,
int *nelemsp)
3464 *nullsp = nulls = (
bool *)
palloc0(nelems *
sizeof(
bool));
3473 for (i = 0; i < nelems; i++)
3476 if (bitmap && (*bitmap & bitmask) == 0)
3483 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3484 errmsg(
"null array element not allowed in this context")));
3497 if (bitmask == 0x100)
3530 if (*bitmap != 0xFF)
3540 if ((*bitmap & bitmask) == 0)
3585 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3586 errmsg(
"cannot compare arrays of different element types")));
3589 if (ndims1 != ndims2 ||
3590 memcmp(dims1, dims2, ndims1 *
sizeof(
int)) != 0 ||
3591 memcmp(lbs1, lbs2, ndims1 *
sizeof(
int)) != 0)
3602 if (typentry ==
NULL ||
3603 typentry->
type_id != element_type)
3609 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
3610 errmsg(
"could not identify an equality operator for type %s",
3612 fcinfo->flinfo->fn_extra = (
void *) typentry;
3614 typlen = typentry->
typlen;
3629 for (i = 0; i < nitems; i++)
3639 typlen, typbyval, typalign);
3641 typlen, typbyval, typalign);
3646 if (isnull1 && isnull2)
3648 if (isnull1 || isnull2)
3657 locfcinfo.
arg[0] = elt1;
3658 locfcinfo.
arg[1] = elt2;
3661 locfcinfo.
isnull =
false;
3756 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3757 errmsg(
"cannot compare arrays of different element types")));
3766 if (typentry ==
NULL ||
3767 typentry->
type_id != element_type)
3773 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
3774 errmsg(
"could not identify a comparison function for type %s",
3778 typlen = typentry->
typlen;
3789 min_nitems =
Min(nitems1, nitems2);
3793 for (i = 0; i < min_nitems; i++)
3802 elt1 =
array_iter_next(&it1, &isnull1, i, typlen, typbyval, typalign);
3803 elt2 =
array_iter_next(&it2, &isnull2, i, typlen, typbyval, typalign);
3808 if (isnull1 && isnull2)
3824 locfcinfo.
arg[0] = elt1;
3825 locfcinfo.
arg[1] = elt2;
3828 locfcinfo.
isnull =
false;
3856 if (nitems1 != nitems2)
3857 result = (nitems1 < nitems2) ? -1 : 1;
3858 else if (ndims1 != ndims2)
3859 result = (ndims1 < ndims2) ? -1 : 1;
3862 for (i = 0; i < ndims1; i++)
3864 if (dims1[i] != dims2[i])
3866 result = (dims1[
i] < dims2[
i]) ? -1 : 1;
3875 for (i = 0; i < ndims1; i++)
3877 if (lbound1[i] != lbound2[i])
3879 result = (lbound1[
i] < lbound2[
i]) ? -1 : 1;
3925 if (typentry ==
NULL ||
3926 typentry->
type_id != element_type)
3932 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
3933 errmsg(
"could not identify a hash function for type %s",
3935 fcinfo->flinfo->fn_extra = (
void *) typentry;
3937 typlen = typentry->
typlen;
3951 for (i = 0; i < nitems; i++)
3968 locfcinfo.
arg[0] = elt;
3970 locfcinfo.
isnull =
false;
3985 result = (result << 5) - result + elthash;
4011 bool matchall,
void **fn_extra)
4013 bool result = matchall;
4030 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4031 errmsg(
"cannot compare arrays of different element types")));
4040 if (typentry ==
NULL ||
4041 typentry->
type_id != element_type)
4047 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
4048 errmsg(
"could not identify an equality operator for type %s",
4050 *fn_extra = (
void *) typentry;
4052 typlen = typentry->
typlen;
4071 element_type, typlen, typbyval, typalign,
4072 &values2, &nulls2, &nelems2);
4084 for (i = 0; i < nelems1; i++)
4090 elt1 =
array_iter_next(&it1, &isnull1, i, typlen, typbyval, typalign);
4107 for (j = 0; j < nelems2; j++)
4109 Datum elt2 = values2[j];
4110 bool isnull2 = nulls2 ? nulls2[j] :
false;
4119 locfcinfo.
arg[0] = elt1;
4120 locfcinfo.
arg[1] = elt2;
4123 locfcinfo.
isnull =
false;
4161 &fcinfo->flinfo->fn_extra);
4179 &fcinfo->flinfo->fn_extra);
4197 &fcinfo->flinfo->fn_extra);
4234 if (slice_ndim < 0 || slice_ndim >
ARR_NDIM(arr))
4235 elog(
ERROR,
"invalid arguments to array_create_iterator");
4240 iterator->
arr = arr;
4346 for (i = 0; i < iterator->
slice_len; i++)
4412 if (nullbitmap ==
NULL)
4414 if (nullbitmap[offset / 8] & (1 << (offset % 8)))
4431 nullbitmap += offset / 8;
4432 bitmask = 1 << (offset % 8);
4434 *nullbitmap &= ~bitmask;
4436 *nullbitmap |= bitmask;
4496 int typlen,
bool typbyval,
char typalign)
4502 if (typlen > 0 && !nullbitmap)
4508 nullbitmap += offset / 8;
4509 bitmask = 1 << (offset % 8);
4511 for (i = 0; i < nitems; i++)
4513 if (*nullbitmap & bitmask)
4519 if (bitmask == 0x100)
4528 for (i = 0; i < nitems; i++)
4544 int typlen,
bool typbyval,
char typalign)
4546 return array_seek(ptr, offset, nullbitmap, nitems,
4547 typlen, typbyval, typalign) - ptr;
4566 char *srcptr,
int offset,
bits8 *nullbitmap,
4567 int typlen,
bool typbyval,
char typalign)
4572 typlen, typbyval, typalign);
4573 memcpy(destptr, srcptr, numbytes);
4596 const bits8 *srcbitmap,
int srcoffset,
4607 destbitmap += destoffset / 8;
4608 destbitmask = 1 << (destoffset % 8);
4609 destbitval = *destbitmap;
4612 srcbitmap += srcoffset / 8;
4613 srcbitmask = 1 << (srcoffset % 8);
4614 srcbitval = *srcbitmap;
4615 while (nitems-- > 0)
4617 if (srcbitval & srcbitmask)
4618 destbitval |= destbitmask;
4620 destbitval &= ~destbitmask;
4622 if (destbitmask == 0x100)
4624 *destbitmap++ = destbitval;
4627 destbitval = *destbitmap;
4630 if (srcbitmask == 0x100)
4635 srcbitval = *srcbitmap;
4638 if (destbitmask != 1)
4639 *destbitmap = destbitval;
4643 while (nitems-- > 0)
4645 destbitval |= destbitmask;
4647 if (destbitmask == 0x100)
4649 *destbitmap++ = destbitval;
4652 destbitval = *destbitmap;
4655 if (destbitmask != 1)
4656 *destbitmap = destbitval;
4667 int ndim,
int *dim,
int *lb,
4669 int typlen,
bool typbyval,
char typalign)
4685 if (typlen > 0 && !arraynullsptr)
4690 ptr =
array_seek(arraydataptr, 0, arraynullsptr, src_offset,
4691 typlen, typbyval, typalign);
4694 for (i = 0; i < ndim; i++)
4701 ptr =
array_seek(ptr, src_offset, arraynullsptr, dist[j],
4702 typlen, typbyval, typalign);
4703 src_offset += dist[j];
4731 bits8 *arraynullsptr,
4752 srcdataptr =
array_seek(arraydataptr, 0, arraynullsptr, src_offset,
4753 typlen, typbyval, typalign);
4757 for (i = 0; i < ndim; i++)
4766 srcdataptr =
array_seek(srcdataptr, src_offset, arraynullsptr,
4768 typlen, typbyval, typalign);
4769 src_offset += dist[j];
4772 srcdataptr, src_offset, arraynullsptr,
4773 typlen, typbyval, typalign);
4776 arraynullsptr, src_offset,
4833 origPtr, 0, origBitmap,
4834 typlen, typbyval, typalign);
4839 orig_offset = dest_offset;
4843 for (i = 0; i < ndim; i++)
4853 origPtr, orig_offset, origBitmap,
4854 typlen, typbyval, typalign);
4859 origBitmap, orig_offset,
4861 dest_offset += dist[j];
4862 orig_offset += dist[j];
4866 srcPtr, src_offset, srcBitmap,
4867 typlen, typbyval, typalign);
4870 srcBitmap, src_offset,
4877 origPtr =
array_seek(origPtr, orig_offset, origBitmap, 1,
4878 typlen, typbyval, typalign);
4883 array_copy(destPtr, orignitems - orig_offset,
4884 origPtr, orig_offset, origBitmap,
4885 typlen, typbyval, typalign);
4888 origBitmap, orig_offset,
4889 orignitems - orig_offset);
4939 astate->
alen = (subcontext ? 64 : 8);
4943 astate->
dnulls = (
bool *)
4965 Datum dvalue,
bool disnull,
4989 astate->
dnulls = (
bool *)
5003 if (astate->
typlen == -1)
5036 ndims = (astate->
nelems > 0) ? 1 : 0;
5037 dims[0] = astate->
nelems;
5126 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5127 errmsg(
"data type %s is not an array type",
5134 "accumArrayResultArr",
5162 Datum dvalue,
bool disnull,
5183 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5184 errmsg(
"cannot accumulate null arrays")));
5204 if (astate->
ndims == 0)
5211 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5212 errmsg(
"cannot accumulate empty arrays")));
5215 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5216 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
5223 astate->
ndims = ndims + 1;
5224 astate->
dims[0] = 0;
5225 memcpy(&astate->
dims[1], dims, ndims *
sizeof(
int));
5227 memcpy(&astate->
lbs[1], lbs, ndims *
sizeof(
int));
5231 while (astate->
abytes <= ndatabytes)
5238 if (astate->
ndims != ndims + 1)
5240 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5241 errmsg(
"cannot accumulate arrays of different dimensionality")));
5242 for (i = 0; i < ndims; i++)
5244 if (astate->
dims[i + 1] != dims[i] || astate->
lbs[i + 1] != lbs[i])
5246 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5247 errmsg(
"cannot accumulate arrays of different dimensionality")));
5254 astate->
nbytes + ndatabytes);
5265 memcpy(astate->
data + astate->
nbytes, data, ndatabytes);
5266 astate->
nbytes += ndatabytes;
5271 int newnitems = astate->
nitems + nitems;
5280 while (astate->
aitems <= newnitems)
5287 else if (newnitems > astate->
aitems)
5298 astate->
nitems += nitems;
5299 astate->
dims[0] += 1;
5328 if (astate->
ndims == 0)
5343 nbytes += dataoffset;
5439 Datum dvalue,
bool disnull,
5449 input_type, rcontext);
5453 input_type, rcontext);
5548 if (reqdim <= 0 || reqdim >
AARR_NDIM(v))
5560 fctx->
lower = lb[reqdim - 1];
5561 fctx->
upper = dimv[reqdim - 1] + lb[reqdim - 1] - 1;
5612 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5613 errmsg(
"dimension array or low bound array cannot be null")));
5631 elog(
ERROR,
"could not determine data type of input");
5652 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5653 errmsg(
"dimension array or low bound array cannot be null")));
5670 elog(
ERROR,
"could not determine data type of input");
5678 Oid elmtype,
int dataoffset)
5684 result->
ndim = ndims;
5687 memcpy(
ARR_DIMS(result), dimv, ndims *
sizeof(
int));
5688 memcpy(
ARR_LBOUND(result), lbsv, ndims *
sizeof(
int));
5714 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5715 errmsg(
"wrong number of array subscripts"),
5716 errdetail(
"Dimension array must be one dimensional.")));
5720 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5721 errmsg(
"wrong range of array subscripts"),
5722 errdetail(
"Lower bound of dimension array must be one.")));
5726 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5727 errmsg(
"dimension values cannot be null")));
5734 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5735 errmsg(
"invalid number of dimensions: %d", ndims)));
5738 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5739 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
5746 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5747 errmsg(
"wrong number of array subscripts"),
5748 errdetail(
"Dimension array must be one dimensional.")));
5752 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5753 errmsg(
"wrong range of array subscripts"),
5754 errdetail(
"Lower bound of dimension array must be one.")));
5758 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5759 errmsg(
"dimension values cannot be null")));
5763 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5764 errmsg(
"wrong number of array subscripts"),
5765 errdetail(
"Low bound array has different size than dimensions array.")));
5773 for (i = 0; i <
MAXDIM; i++)
5790 if (my_extra ==
NULL)
5808 elmlen = my_extra->
typlen;
5828 totbytes = nbytes * nitems;
5831 if (totbytes / nbytes != nitems ||
5834 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5835 errmsg(
"array size exceeds the maximum allowed (%d)",
5848 for (i = 0; i < nitems; i++)
5857 nbytes = dataoffset;
5860 elmtype, dataoffset);
5883 } array_unnest_fctx;
5886 array_unnest_fctx *fctx;
5912 fctx = (array_unnest_fctx *)
palloc(
sizeof(array_unnest_fctx));
5940 if (fctx->nextelem < fctx->numelems)
5942 int offset = fctx->nextelem++;
5946 fctx->elmlen, fctx->elmbyval, fctx->elmalign);
5968 Datum search,
bool search_isnull,
5969 Datum replace,
bool replace_isnull,
5970 bool remove,
Oid collation,
5991 bool changed =
false;
6008 if (
remove && ndim > 1)
6010 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6011 errmsg(
"removing elements from multidimensional arrays is not supported")));
6018 if (typentry ==
NULL ||
6019 typentry->
type_id != element_type)
6025 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
6026 errmsg(
"could not identify an equality operator for type %s",
6030 typlen = typentry->
typlen;
6043 if (!replace_isnull)
6053 nulls = (
bool *)
palloc(nitems *
sizeof(
bool));
6062 for (i = 0; i < nitems; i++)
6070 if (bitmap && (*bitmap & bitmask) == 0)
6081 else if (!replace_isnull)
6083 values[nresult] = replace;
6092 elt =
fetch_att(arraydataptr, typbyval, typlen);
6099 values[nresult] = elt;
6106 locfcinfo.
arg[0] = elt;
6107 locfcinfo.
arg[1] = search;
6110 locfcinfo.
isnull =
false;
6115 values[nresult] = elt;
6125 values[nresult] = replace;
6126 isNull = replace_isnull;
6134 nulls[nresult] = isNull;
6145 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
6146 errmsg(
"array size exceeds the maximum allowed (%d)",
6156 if (bitmask == 0x100)
6186 nbytes += dataoffset;
6195 result->
ndim = ndim;
6209 values, nulls, nresult,
6210 typlen, typbyval, typalign,
6236 search, search_isnull,
6260 search, search_isnull,
6261 replace, replace_isnull,
6287 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
6288 errmsg(
"thresholds must be one-dimensional array")));
6292 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6293 errmsg(
"thresholds array must not contain NULLs")));
6304 if (typentry ==
NULL ||
6305 typentry->
type_id != element_type)
6311 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
6312 errmsg(
"could not identify a comparison function for type %s",
6314 fcinfo->flinfo->fn_extra = (
void *) typentry;
6321 if (typentry->
typlen > 0)
6323 collation, typentry);
6326 collation, typentry);
6366 while (left < right)
6368 int mid = (left + right) / 2;
6370 if (isnan(thresholds_data[mid]) || op < thresholds_data[mid])
6388 char *thresholds_data;
6389 int typlen = typentry->
typlen;
6390 bool typbyval = typentry->
typbyval;
6407 while (left < right)
6409 int mid = (left + right) / 2;
6413 ptr = thresholds_data + mid * typlen;
6415 locfcinfo.
arg[0] = operand;
6419 locfcinfo.
isnull =
false;
6441 char *thresholds_data;
6442 int typlen = typentry->
typlen;
6443 bool typbyval = typentry->
typbyval;
6444 char typalign = typentry->
typalign;
6457 while (left < right)
6459 int mid = (left + right) / 2;
6465 ptr = thresholds_data;
6466 for (i = left; i < mid; i++)
6472 locfcinfo.
arg[0] = operand;
6476 locfcinfo.
isnull =
false;
Datum btarraycmp(PG_FUNCTION_ARGS)
Datum generate_subscripts(PG_FUNCTION_ARGS)
#define DatumGetUInt32(X)
ArrayIterator array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
Datum makeArrayResultArr(ArrayBuildStateArr *astate, MemoryContext rcontext, bool release)
Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)
Datum array_ne(PG_FUNCTION_ARGS)
#define PG_GETARG_INT32(n)
static void skip(struct vars *v)
void MemoryContextDelete(MemoryContext context)
Datum array_send(PG_FUNCTION_ARGS)
static bool array_isspace(char ch)
#define PG_DETOAST_DATUM_COPY(datum)
Datum array_fill_with_lower_bounds(PG_FUNCTION_ARGS)
Datum array_ge(PG_FUNCTION_ARGS)
#define ARR_OVERHEAD_NONULLS(ndims)
ArrayBuildStateAny * initArrayResultAny(Oid input_type, MemoryContext rcontext, bool subcontext)
#define att_align_nominal(cur_offset, attalign)
void deconstruct_expanded_array(ExpandedArrayHeader *eah)
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
Datum array_map(FunctionCallInfo fcinfo, Oid retType, ArrayMapState *amstate)
static ArrayType * array_fill_internal(ArrayType *dims, ArrayType *lbs, Datum value, bool isnull, Oid elmtype, FunctionCallInfo fcinfo)
Datum array_unnest(PG_FUNCTION_ARGS)
static ArrayType * create_array_envelope(int ndims, int *dimv, int *lbv, int nbytes, Oid elmtype, int dataoffset)
Datum array_replace(PG_FUNCTION_ARGS)
int ArrayGetOffset(int n, const int *dim, const int *lb, const int *indx)
static int ArrayCastAndSet(Datum src, int typlen, bool typbyval, char typalign, char *dest)
static Datum array_iter_next(array_iter *it, bool *isnull, int i, int elmlen, bool elmbyval, char elmalign)
Oid get_element_type(Oid typid)
#define SRF_IS_FIRSTCALL()
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
#define PointerGetDatum(X)
#define PG_GETARG_DATUM(n)
void mda_get_prod(int n, const int *range, int *prod)
Oid get_array_type(Oid typid)
char * pstrdup(const char *in)
#define TYPECACHE_EQ_OPR_FINFO
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
static int array_slice_size(char *arraydataptr, bits8 *arraynullsptr, int ndim, int *dim, int *lb, int *st, int *endp, int typlen, bool typbyval, char typalign)
StringInfoData * StringInfo
#define TYPECACHE_HASH_PROC_FINFO
int ArrayGetNItems(int ndim, const int *dims)
Datum expand_array(Datum arraydatum, MemoryContext parentcontext, ArrayMetaState *metacache)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define PG_RETURN_INT32(x)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
int errcode(int sqlerrcode)
#define MemSet(start, val, len)
Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
#define PG_GETARG_POINTER(n)
Datum array_recv(PG_FUNCTION_ARGS)
static void array_extract_slice(ArrayType *newarray, int ndim, int *dim, int *lb, char *arraydataptr, bits8 *arraynullsptr, int *st, int *endp, int typlen, bool typbyval, char typalign)
static int array_cmp(FunctionCallInfo fcinfo)
#define PG_GETARG_BOOL(n)
int pg_strcasecmp(const char *s1, const char *s2)
#define PG_RETURN_BYTEA_P(x)
Datum array_cardinality(PG_FUNCTION_ARGS)
ArrayType * construct_empty_array(Oid elmtype)
ArrayBuildState * scalarstate
#define OidIsValid(objectId)
#define SRF_PERCALL_SETUP()
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
Datum array_out(PG_FUNCTION_ARGS)
#define PG_GET_COLLATION()
#define ALLOCSET_DEFAULT_MINSIZE
static int array_copy(char *destptr, int nitems, char *srcptr, int offset, bits8 *nullbitmap, int typlen, bool typbyval, char typalign)
#define PG_RETURN_UINT32(x)
static void ReadArrayStr(char *arrayStr, const char *origStr, int nitems, int ndim, int *dim, FmgrInfo *inputproc, Oid typioparam, int32 typmod, char typdelim, int typlen, bool typbyval, char typalign, Datum *values, bool *nulls, bool *hasnulls, int32 *nbytes)
Datum array_gt(PG_FUNCTION_ARGS)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
ArrayBuildStateArr * initArrayResultArr(Oid array_type, Oid element_type, MemoryContext rcontext, bool subcontext)
#define ARR_DATA_OFFSET(a)
Datum arrayoverlap(PG_FUNCTION_ARGS)
Datum array_get_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
#define SRF_RETURN_NEXT(_funcctx, _result)
struct ArrayIteratorData ArrayIteratorData
#define PG_GETARG_ARRAYTYPE_P(n)
void pfree(void *pointer)
bool array_iterate(ArrayIterator iterator, Datum *value, bool *isnull)
#define PG_GETARG_ANY_ARRAY(n)
ExpandedArrayHeader * DatumGetExpandedArray(Datum d)
static int width_bucket_array_variable(Datum operand, ArrayType *thresholds, Oid collation, TypeCacheEntry *typentry)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
ArrayBuildStateArr * accumArrayResultArr(ArrayBuildStateArr *astate, Datum dvalue, bool disnull, Oid array_type, MemoryContext rcontext)
static bool array_contain_compare(AnyArrayType *array1, AnyArrayType *array2, Oid collation, bool matchall, void **fn_extra)
#define FunctionCallInvoke(fcinfo)
static Datum array_get_element_expanded(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
static int width_bucket_array_fixed(Datum operand, ArrayType *thresholds, Oid collation, TypeCacheEntry *typentry)
static void array_iter_setup(array_iter *it, AnyArrayType *a)
static Datum array_set_element_expanded(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
int errdetail(const char *fmt,...)
struct generate_subscripts_fctx generate_subscripts_fctx
Datum array_upper(PG_FUNCTION_ARGS)
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
bool argnull[FUNC_MAX_ARGS]
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
#define PG_RETURN_ARRAYTYPE_P(x)
#define att_addlength_pointer(cur_offset, attlen, attptr)
#define ereport(elevel, rest)
void mda_get_offset_values(int n, int *dist, const int *prod, const int *span)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Datum datumCopy(Datum value, bool typByVal, int typLen)
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
#define AllocSizeIsValid(size)
ArrayBuildStateAny * accumArrayResultAny(ArrayBuildStateAny *astate, Datum dvalue, bool disnull, Oid input_type, MemoryContext rcontext)
ExpandedObjectHeader * DatumGetEOHP(Datum d)
static void ReadArrayBinary(StringInfo buf, int nitems, FmgrInfo *receiveproc, Oid typioparam, int32 typmod, int typlen, bool typbyval, char typalign, Datum *values, bool *nulls, bool *hasnulls, int32 *nbytes)
ExpandedArrayHeader * construct_empty_expanded_array(Oid element_type, MemoryContext parentcontext, ArrayMetaState *metacache)
ArrayBuildStateArr * arraystate
#define store_att_byval(T, newdatum, attlen)
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
void * palloc0(Size size)
#define DatumGetFloat8(X)
#define PG_RETURN_BOOL(x)
#define PG_RETURN_DATUM(x)
Datum generate_subscripts_nodir(PG_FUNCTION_ARGS)
Datum arraycontains(PG_FUNCTION_ARGS)
void mda_get_range(int n, int *span, const int *st, const int *endp)
Datum arraycontained(PG_FUNCTION_ARGS)
static void array_set_isnull(bits8 *nullbitmap, int offset, bool isNull)
void * MemoryContextAllocZero(MemoryContext context, Size size)
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
static ArrayType * array_replace_internal(ArrayType *array, Datum search, bool search_isnull, Datum replace, bool replace_isnull, bool remove, Oid collation, FunctionCallInfo fcinfo)
Datum array_ndims(PG_FUNCTION_ARGS)
Datum array_eq(PG_FUNCTION_ARGS)
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
#define PG_RETURN_TEXT_P(x)
void array_free_iterator(ArrayIterator iterator)
text * cstring_to_text(const char *s)
Datum array_le(PG_FUNCTION_ARGS)
Datum array_lt(PG_FUNCTION_ARGS)
#define Assert(condition)
static void array_insert_slice(ArrayType *destArray, ArrayType *origArray, ArrayType *srcArray, int ndim, int *dim, int *lb, int *st, int *endp, int typlen, bool typbyval, char typalign)
static char * array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems, int typlen, bool typbyval, char typalign)
#define PG_RETURN_CSTRING(x)
MemoryContext multi_call_memory_ctx
static Datum ArrayCast(char *value, bool byval, int len)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define AARR_FREE_IF_COPY(array, n)
Datum array_set_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, Datum srcArrayDatum, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
#define PG_FREE_IF_COPY(ptr, n)
Datum width_bucket_array(PG_FUNCTION_ARGS)
Datum array_larger(PG_FUNCTION_ARGS)
static bool array_get_isnull(const bits8 *nullbitmap, int offset)
void * repalloc(void *pointer, Size size)
static int ArrayCount(const char *str, int *dim, char typdelim)
void CopyArrayEls(ArrayType *array, Datum *values, bool *nulls, int nitems, int typlen, bool typbyval, char typalign, bool freedata)
#define VARATT_IS_EXPANDED_HEADER(PTR)
Datum array_dims(PG_FUNCTION_ARGS)
#define DatumGetPointer(X)
Datum array_length(PG_FUNCTION_ARGS)
#define EOHPGetRWDatum(eohptr)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
static Datum values[MAXATTR]
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Datum makeArrayResultAny(ArrayBuildStateAny *astate, MemoryContext rcontext, bool release)
int mda_next_tuple(int n, int *curr, const int *span)
Datum array_smaller(PG_FUNCTION_ARGS)
#define att_addlength_datum(cur_offset, attlen, attdatum)
int errmsg(const char *fmt,...)
#define fetch_att(T, attbyval, attlen)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define ALLOCSET_DEFAULT_INITSIZE
#define PG_GETARG_CSTRING(n)
#define PG_DETOAST_DATUM(datum)
static int width_bucket_array_float8(Datum operand, ArrayType *thresholds)
#define ALLOCSET_DEFAULT_MAXSIZE
Datum array_fill(PG_FUNCTION_ARGS)
#define TYPECACHE_CMP_PROC_FINFO
Datum array_remove(PG_FUNCTION_ARGS)
#define SET_VARSIZE(PTR, len)
Datum hash_array(PG_FUNCTION_ARGS)
static int array_nelems_size(char *ptr, int offset, bits8 *nullbitmap, int nitems, int typlen, bool typbyval, char typalign)
Datum array_lower(PG_FUNCTION_ARGS)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
bool array_contains_nulls(ArrayType *array)
#define PointerIsValid(pointer)
MemoryContext eoh_context
#define ARR_NULLBITMAP(a)
Datum array_in(PG_FUNCTION_ARGS)
int ArrayGetOffset0(int n, const int *tup, const int *scale)
#define SRF_RETURN_DONE(_funcctx)
#define DatumGetArrayTypeP(X)
#define SRF_FIRSTCALL_INIT()
void get_type_io_data(Oid typid, IOFuncSelector which_func, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *func)