24 #define ARRAYACCESS_INCLUDE_DEFINITIONS
49 #define AARR_FREE_IF_COPY(array,n) \
51 if (!VARATT_IS_EXPANDED_HEADER(array)) \
52 PG_FREE_IF_COPY(array, n); \
93 static int ArrayCount(
const char *str,
int *dim,
char typdelim);
94 static void ReadArrayStr(
char *arrayStr,
const char *origStr,
95 int nitems,
int ndim,
int *dim,
98 int typlen,
bool typbyval,
char typalign,
100 bool *hasnulls,
int32 *nbytes);
103 int typlen,
bool typbyval,
char typalign,
105 bool *hasnulls,
int32 *nbytes);
107 int nSubscripts,
int *indx,
109 int elmlen,
bool elmbyval,
char elmalign,
112 int nSubscripts,
int *indx,
113 Datum dataValue,
bool isNull,
115 int elmlen,
bool elmbyval,
char elmalign);
120 int typlen,
bool typbyval,
char typalign,
122 static char *
array_seek(
char *ptr,
int offset,
bits8 *nullbitmap,
int nitems,
123 int typlen,
bool typbyval,
char typalign);
125 int nitems,
int typlen,
bool typbyval,
char typalign);
126 static int array_copy(
char *destptr,
int nitems,
127 char *srcptr,
int offset,
bits8 *nullbitmap,
128 int typlen,
bool typbyval,
char typalign);
130 int ndim,
int *dim,
int *lb,
132 int typlen,
bool typbyval,
char typalign);
134 int ndim,
int *dim,
int *lb,
135 char *arraydataptr,
bits8 *arraynullsptr,
137 int typlen,
bool typbyval,
char typalign);
140 int ndim,
int *dim,
int *lb,
142 int typlen,
bool typbyval,
char typalign);
145 Oid elmtype,
int dataoffset);
150 Datum search,
bool search_isnull,
151 Datum replace,
bool replace_isnull,
152 bool remove,
Oid collation,
206 if (my_extra ==
NULL)
227 typlen = my_extra->
typlen;
262 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
263 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
266 for (q = p; isdigit((
unsigned char) *q) || (*q ==
'-') || (*q ==
'+'); q++)
270 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
271 errmsg(
"malformed array literal: \"%s\"",
string),
272 errdetail(
"\"[\" must introduce explicitly-specified array dimensions.")));
278 lBound[ndim] = atoi(p);
280 for (q = p; isdigit((
unsigned char) *q) || (*q ==
'-') || (*q ==
'+'); q++)
284 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
285 errmsg(
"malformed array literal: \"%s\"",
string),
286 errdetail(
"Missing array dimension value.")));
295 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
296 errmsg(
"malformed array literal: \"%s\"",
string),
297 errdetail(
"Missing \"%s\" after array dimensions.",
303 if (ub < lBound[ndim])
305 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
306 errmsg(
"upper bound cannot be less than lower bound")));
308 dim[ndim] = ub - lBound[ndim] + 1;
317 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
318 errmsg(
"malformed array literal: \"%s\"",
string),
319 errdetail(
"Array value must start with \"{\" or dimension information.")));
321 for (i = 0; i < ndim; i++)
332 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
333 errmsg(
"malformed array literal: \"%s\"",
string),
334 errdetail(
"Missing \"%s\" after array dimensions.",
346 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
347 errmsg(
"malformed array literal: \"%s\"",
string),
348 errdetail(
"Array contents must start with \"{\".")));
349 ndim_braces =
ArrayCount(p, dim_braces, typdelim);
350 if (ndim_braces != ndim)
352 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
353 errmsg(
"malformed array literal: \"%s\"",
string),
354 errdetail(
"Specified array dimensions do not match array contents.")));
355 for (i = 0; i < ndim; ++
i)
357 if (dim[i] != dim_braces[i])
359 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
360 errmsg(
"malformed array literal: \"%s\"",
string),
361 errdetail(
"Specified array dimensions do not match array contents.")));
366 printf(
"array_in- ndim %d (", ndim);
367 for (i = 0; i < ndim; i++)
369 printf(
" %d", dim[i]);
371 printf(
") for %s\n",
string);
381 nullsPtr = (
bool *)
palloc(nitems *
sizeof(
bool));
384 &my_extra->
proc, typioparam, typmod,
386 typlen, typbyval, typalign,
392 nbytes += dataoffset;
410 memcpy(
ARR_DIMS(retval), dim, ndim *
sizeof(
int));
411 memcpy(
ARR_LBOUND(retval), lBound, ndim *
sizeof(
int));
414 dataPtr, nullsPtr, nitems,
415 typlen, typbyval, typalign,
462 bool in_quotes =
false;
463 bool eoArray =
false;
464 bool empty_array =
true;
470 temp[
i] = dim[
i] = nelems_last[
i] = 0;
477 bool itemdone =
false;
490 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
491 errmsg(
"malformed array literal: \"%s\"", str),
506 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
507 errmsg(
"malformed array literal: \"%s\"", str),
508 errdetail(
"Unexpected \"%c\" character.",
517 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
518 errmsg(
"malformed array literal: \"%s\"", str),
532 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
533 errmsg(
"malformed array literal: \"%s\"", str),
534 errdetail(
"Unexpected array element.")));
535 in_quotes = !in_quotes;
553 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
554 errmsg(
"malformed array literal: \"%s\"", str),
555 errdetail(
"Unexpected \"%c\" character.",
558 if (nest_level >= MAXDIM)
560 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
561 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
562 nest_level + 1, MAXDIM)));
563 temp[nest_level] = 0;
565 if (ndim < nest_level)
583 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
584 errmsg(
"malformed array literal: \"%s\"", str),
585 errdetail(
"Unexpected \"%c\" character.",
590 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
591 errmsg(
"malformed array literal: \"%s\"", str),
592 errdetail(
"Unmatched \"%c\" character.",
'}')));
595 if (nelems_last[nest_level] != 0 &&
596 nelems[nest_level] != nelems_last[nest_level])
598 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
599 errmsg(
"malformed array literal: \"%s\"", str),
600 errdetail(
"Multidimensional arrays must have "
601 "sub-arrays with matching "
603 nelems_last[nest_level] = nelems[nest_level];
604 nelems[nest_level] = 1;
606 eoArray = itemdone =
true;
613 temp[nest_level - 1]++;
620 if (*ptr == typdelim)
632 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
633 errmsg(
"malformed array literal: \"%s\"", str),
634 errdetail(
"Unexpected \"%c\" character.",
641 nelems[nest_level - 1]++;
655 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
656 errmsg(
"malformed array literal: \"%s\"", str),
657 errdetail(
"Unexpected array element.")));
675 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
676 errmsg(
"malformed array literal: \"%s\"", str),
677 errdetail(
"Junk after closing right brace.")));
684 for (
i = 0;
i < ndim; ++
i)
739 bool in_quotes =
false;
740 bool eoArray =
false;
747 MemSet(indx, 0,
sizeof(indx));
750 memset(nulls,
true, nitems *
sizeof(
bool));
770 bool itemdone =
false;
771 bool leadingspace =
true;
772 bool hasquoting =
false;
778 itemstart = dstptr = dstendptr = srcptr;
787 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
788 errmsg(
"malformed array literal: \"%s\"",
796 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
797 errmsg(
"malformed array literal: \"%s\"",
799 *dstptr++ = *srcptr++;
801 leadingspace =
false;
806 in_quotes = !in_quotes;
808 leadingspace =
false;
824 if (nest_level >= ndim)
826 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
827 errmsg(
"malformed array literal: \"%s\"",
830 indx[nest_level - 1] = 0;
834 *dstptr++ = *srcptr++;
841 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
842 errmsg(
"malformed array literal: \"%s\"",
846 indx[nest_level - 1] = 0;
849 eoArray = itemdone =
true;
851 indx[nest_level - 1]++;
855 *dstptr++ = *srcptr++;
859 *dstptr++ = *srcptr++;
860 else if (*srcptr == typdelim)
877 *dstptr++ = *srcptr++;
881 *dstptr++ = *srcptr++;
882 leadingspace =
false;
892 if (i < 0 || i >= nitems)
894 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
895 errmsg(
"malformed array literal: \"%s\"",
919 for (i = 0; i < nitems; i++)
933 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
934 errmsg(
"array size exceeds the maximum allowed (%d)",
977 for (i = 0; i < nitems; i++)
979 if (nulls && nulls[i])
982 elog(
ERROR,
"null array element where not supported");
995 if (bitmask == 0x100)
1004 if (bitmap && bitmask != 1)
1026 dims_str[(
MAXDIM * 33) + 2];
1053 if (my_extra ==
NULL)
1074 typlen = my_extra->
typlen;
1094 for (i = 0; i < ndim; i++)
1108 values = (
char **)
palloc(nitems *
sizeof(
char *));
1109 needquotes = (
bool *)
palloc(nitems *
sizeof(
bool));
1114 for (i = 0; i < nitems; i++)
1122 typlen, typbyval, typalign);
1127 overall_length += 4;
1135 if (values[i][0] ==
'\0')
1142 for (tmp = values[i]; *tmp !=
'\0'; tmp++)
1146 overall_length += 1;
1147 if (ch ==
'"' || ch ==
'\\')
1150 overall_length += 1;
1152 else if (ch ==
'{' || ch ==
'}' || ch == typdelim ||
1158 needquotes[
i] = needquote;
1162 overall_length += 2;
1164 overall_length += 1;
1170 for (i = j = 0, k = 1; i < ndim; i++)
1171 k *= dims[i], j += k;
1178 char *ptr = dims_str;
1180 for (i = 0; i < ndim; i++)
1182 sprintf(ptr,
"[%d:%d]", lb[i], lb[i] + dims[i] - 1);
1189 retval = (
char *)
palloc(strlen(dims_str) + overall_length + 2 * j);
1192 #define APPENDSTR(str) (strcpy(p, (str)), p += strlen(p))
1193 #define APPENDCHAR(ch) (*p++ = (ch), *p = '\0')
1198 for (i = 0; i < ndim; i++)
1204 for (i = j; i < ndim - 1; i++)
1210 for (tmp = values[k]; *tmp; tmp++)
1214 if (ch ==
'"' || ch ==
'\\')
1225 for (i = ndim - 1; i >= 0; i--)
1227 indx[
i] = (indx[
i] + 1) % dims[i];
1286 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1287 errmsg(
"invalid number of dimensions: %d", ndim)));
1290 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1291 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
1295 if (flags != 0 && flags != 1)
1297 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1298 errmsg(
"invalid array flags")));
1301 if (element_type != spec_element_type)
1305 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1306 errmsg(
"wrong element type")));
1309 for (i = 0; i < ndim; i++)
1320 int ub = lBound[
i] + dim[
i] - 1;
1324 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1325 errmsg(
"integer out of range")));
1338 if (my_extra ==
NULL)
1355 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1356 errmsg(
"no binary input function available for type %s",
1369 typlen = my_extra->
typlen;
1375 nullsPtr = (
bool *)
palloc(nitems *
sizeof(
bool));
1377 &my_extra->
proc, typioparam, typmod,
1378 typlen, typbyval, typalign,
1380 &hasnulls, &nbytes);
1384 nbytes += dataoffset;
1393 retval->
ndim = ndim;
1396 memcpy(
ARR_DIMS(retval), dim, ndim *
sizeof(
int));
1397 memcpy(
ARR_LBOUND(retval), lBound, ndim *
sizeof(
int));
1400 dataPtr, nullsPtr, nitems,
1401 typlen, typbyval, typalign,
1449 for (i = 0; i < nitems; i++)
1457 if (itemlen < -1 || itemlen > (buf->
len - buf->
cursor))
1459 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1460 errmsg(
"insufficient data left in message")));
1466 typioparam, typmod);
1478 elem_buf.
maxlen = itemlen + 1;
1479 elem_buf.
len = itemlen;
1489 typioparam, typmod);
1493 if (elem_buf.
cursor != itemlen)
1495 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1496 errmsg(
"improper binary format in array element %d",
1507 for (i = 0; i < nitems; i++)
1521 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1522 errmsg(
"array size exceeds the maximum allowed (%d)",
1526 *hasnulls = hasnull;
1559 if (my_extra ==
NULL)
1576 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1577 errmsg(
"no binary output function available for type %s",
1583 typlen = my_extra->
typlen;
1598 for (i = 0; i < ndim; i++)
1607 for (i = 0; i < nitems; i++)
1614 typlen, typbyval, typalign);
1682 sprintf(p,
"[%d:%d]", lb[i], dimv[i] + lb[i] - 1);
1707 if (reqdim <= 0 || reqdim >
AARR_NDIM(v))
1711 result = lb[reqdim - 1];
1735 if (reqdim <= 0 || reqdim >
AARR_NDIM(v))
1741 result = dimv[reqdim - 1] + lb[reqdim - 1] - 1;
1764 if (reqdim <= 0 || reqdim >
AARR_NDIM(v))
1769 result = dimv[reqdim - 1];
1827 bits8 *arraynullsptr;
1829 if (arraytyplen > 0)
1835 fixedDim[0] = arraytyplen / elmlen;
1840 arraynullsptr =
NULL;
1869 if (ndim != nSubscripts || ndim <= 0 || ndim >
MAXDIM)
1874 for (i = 0; i < ndim; i++)
1876 if (indx[i] < lb[i] || indx[i] >= (dim[i] + lb[i]))
1901 retptr =
array_seek(arraydataptr, 0, arraynullsptr, offset,
1902 elmlen, elmbyval, elmalign);
1903 return ArrayCast(retptr, elmbyval, elmlen);
1911 int nSubscripts,
int *indx,
1913 int elmlen,
bool elmbyval,
char elmalign,
1929 Assert(arraytyplen == -1);
1941 if (ndim != nSubscripts || ndim <= 0 || ndim >
MAXDIM)
1946 for (i = 0; i < ndim; i++)
1948 if (indx[i] < lb[i] || indx[i] >= (dim[i] + lb[i]))
1972 if (dnulls && dnulls[offset])
1985 return dvalues[offset];
2033 bits8 *arraynullsptr;
2038 if (arraytyplen > 0)
2047 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2048 errmsg(
"slices of fixed-length arrays not implemented")));
2056 fixedDim[0] = arraytyplen / elmlen;
2062 arraynullsptr =
NULL;
2082 if (ndim < nSubscripts || ndim <= 0 || ndim >
MAXDIM)
2085 for (i = 0; i < nSubscripts; i++)
2087 if (lowerIndx[i] < lb[i])
2088 lowerIndx[
i] = lb[
i];
2089 if (upperIndx[i] >= (dim[i] + lb[i]))
2090 upperIndx[
i] = dim[
i] + lb[
i] - 1;
2091 if (lowerIndx[i] > upperIndx[i])
2095 for (; i < ndim; i++)
2097 lowerIndx[
i] = lb[
i];
2098 upperIndx[
i] = dim[
i] + lb[
i] - 1;
2099 if (lowerIndx[i] > upperIndx[i])
2107 lowerIndx, upperIndx,
2108 elmlen, elmbyval, elmalign);
2117 bytes += dataoffset;
2127 newarray->
ndim = ndim;
2130 memcpy(
ARR_DIMS(newarray), span, ndim *
sizeof(
int));
2137 for (i = 0; i < ndim; i++)
2142 arraydataptr, arraynullsptr,
2143 lowerIndx, upperIndx,
2144 elmlen, elmbyval, elmalign);
2201 bits8 *oldnullbitmap;
2215 if (arraytyplen > 0)
2223 if (nSubscripts != 1)
2225 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2226 errmsg(
"wrong number of array subscripts")));
2228 if (indx[0] < 0 || indx[0] * elmlen >= arraytyplen)
2230 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2231 errmsg(
"array subscript out of range")));
2235 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2236 errmsg(
"cannot assign null value to an element of a fixed-length array")));
2238 resultarray = (
char *)
palloc(arraytyplen);
2240 elt_ptr = (
char *) resultarray + indx[0] * elmlen;
2245 if (nSubscripts <= 0 || nSubscripts >
MAXDIM)
2247 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2248 errmsg(
"wrong number of array subscripts")));
2251 if (elmlen == -1 && !isNull)
2282 for (i = 0; i < nSubscripts; i++)
2289 nSubscripts, dim, lb,
2291 elmlen, elmbyval, elmalign));
2294 if (ndim != nSubscripts)
2296 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2297 errmsg(
"wrong number of array subscripts")));
2300 memcpy(dim,
ARR_DIMS(array), ndim *
sizeof(
int));
2301 memcpy(lb,
ARR_LBOUND(array), ndim *
sizeof(
int));
2304 addedbefore = addedafter = 0;
2311 if (indx[0] < lb[0])
2313 addedbefore = lb[0] - indx[0];
2314 dim[0] += addedbefore;
2316 if (addedbefore > 1)
2319 if (indx[0] >= (dim[0] + lb[0]))
2321 addedafter = indx[0] - (dim[0] + lb[0]) + 1;
2322 dim[0] += addedafter;
2333 for (i = 0; i < ndim; i++)
2335 if (indx[i] < lb[i] ||
2336 indx[i] >= (dim[i] + lb[i]))
2338 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2339 errmsg(
"array subscript out of range")));
2354 olddatasize =
ARR_SIZE(array) - oldoverheadlen;
2360 lenafter = olddatasize;
2362 else if (addedafter)
2365 lenbefore = olddatasize;
2373 elmlen, elmbyval, elmalign);
2382 lenafter = (int) (olddatasize - lenbefore - olditemlen);
2393 newsize = overheadlen + lenbefore + newitemlen + lenafter;
2400 newarray->
ndim = ndim;
2401 newarray->
dataoffset = newhasnulls ? overheadlen : 0;
2403 memcpy(
ARR_DIMS(newarray), dim, ndim *
sizeof(
int));
2404 memcpy(
ARR_LBOUND(newarray), lb, ndim *
sizeof(
int));
2409 memcpy((
char *) newarray + overheadlen,
2410 (
char *) array + oldoverheadlen,
2414 (
char *) newarray + overheadlen + lenbefore);
2415 memcpy((
char *) newarray + overheadlen + lenbefore + newitemlen,
2416 (
char *) array + oldoverheadlen + lenbefore + olditemlen,
2430 MemSet(newnullbitmap, 0, (newnitems + 7) / 8);
2446 if (addedafter == 0)
2448 oldnullbitmap, offset + 1,
2449 oldnitems - offset - 1);
2465 int nSubscripts,
int *indx,
2466 Datum dataValue,
bool isNull,
2468 int elmlen,
bool elmbyval,
char elmalign)
2488 Assert(arraytyplen == -1);
2500 memcpy(dim, eah->
dims, ndim *
sizeof(
int));
2501 memcpy(lb, eah->
lbound, ndim *
sizeof(
int));
2502 dimschanged =
false;
2517 nSubscripts *
sizeof(
int));
2519 nSubscripts *
sizeof(
int));
2523 for (i = 0; i < nSubscripts; i++)
2530 else if (ndim != nSubscripts)
2532 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2533 errmsg(
"wrong number of array subscripts")));
2559 newhasnulls = ((dnulls !=
NULL) || isNull);
2560 addedbefore = addedafter = 0;
2567 if (indx[0] < lb[0])
2569 addedbefore = lb[0] - indx[0];
2570 dim[0] += addedbefore;
2573 if (addedbefore > 1)
2576 if (indx[0] >= (dim[0] + lb[0]))
2578 addedafter = indx[0] - (dim[0] + lb[0]) + 1;
2579 dim[0] += addedafter;
2591 for (i = 0; i < ndim; i++)
2593 if (indx[i] < lb[i] ||
2594 indx[i] >= (dim[i] + lb[i]))
2596 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2597 errmsg(
"array subscript out of range")));
2608 int newlen = dim[0] + dim[0] / 8;
2610 newlen =
Max(newlen, dim[0]);
2614 eah->
dnulls = dnulls = (
bool *)
2615 repalloc(dnulls, newlen *
sizeof(
bool));
2623 if (newhasnulls && dnulls ==
NULL)
2624 eah->
dnulls = dnulls = (
bool *)
2642 memcpy(eah->
dims, dim, ndim *
sizeof(
int));
2643 memcpy(eah->
lbound, lb, ndim *
sizeof(
int));
2647 if (addedbefore > 0)
2650 for (i = 0; i < addedbefore; i++)
2651 dvalues[i] = (
Datum) 0;
2654 memmove(dnulls + addedbefore, dnulls, eah->
nelems *
sizeof(
bool));
2655 for (i = 0; i < addedbefore; i++)
2658 eah->
nelems += addedbefore;
2664 for (i = 0; i < addedafter; i++)
2668 for (i = 0; i < addedafter; i++)
2669 dnulls[eah->
nelems + i] =
true;
2671 eah->
nelems += addedafter;
2675 if (!eah->
typbyval && (dnulls ==
NULL || !dnulls[offset]))
2681 dvalues[offset] = dataValue;
2683 dnulls[offset] = isNull;
2693 if (oldValue < eah->fstartptr || oldValue >= eah->
fendptr)
2741 Datum srcArrayDatum,
2777 if (arraytyplen > 0)
2783 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2784 errmsg(
"updates on slices of fixed-length arrays not implemented")));
2808 &dvalues, &dnulls, &nelems);
2810 for (i = 0; i < nSubscripts; i++)
2812 dim[
i] = 1 + upperIndx[
i] - lowerIndx[
i];
2813 lb[
i] = lowerIndx[
i];
2819 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2820 errmsg(
"source array too small")));
2824 elmlen, elmbyval, elmalign));
2827 if (ndim < nSubscripts || ndim <= 0 || ndim >
MAXDIM)
2829 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2830 errmsg(
"wrong number of array subscripts")));
2833 memcpy(dim,
ARR_DIMS(array), ndim *
sizeof(
int));
2834 memcpy(lb,
ARR_LBOUND(array), ndim *
sizeof(
int));
2837 addedbefore = addedafter = 0;
2844 Assert(nSubscripts == 1);
2845 if (lowerIndx[0] > upperIndx[0])
2847 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2848 errmsg(
"upper bound cannot be less than lower bound")));
2849 if (lowerIndx[0] < lb[0])
2851 if (upperIndx[0] < lb[0] - 1)
2853 addedbefore = lb[0] - lowerIndx[0];
2854 dim[0] += addedbefore;
2855 lb[0] = lowerIndx[0];
2857 if (upperIndx[0] >= (dim[0] + lb[0]))
2859 if (lowerIndx[0] > (dim[0] + lb[0]))
2861 addedafter = upperIndx[0] - (dim[0] + lb[0]) + 1;
2862 dim[0] += addedafter;
2871 for (i = 0; i < nSubscripts; i++)
2873 if (lowerIndx[i] > upperIndx[i])
2875 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2876 errmsg(
"upper bound cannot be less than lower bound")));
2877 if (lowerIndx[i] < lb[i] ||
2878 upperIndx[i] >= (dim[i] + lb[i]))
2880 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2881 errmsg(
"array subscript out of range")));
2884 for (; i < ndim; i++)
2886 lowerIndx[
i] = lb[
i];
2887 upperIndx[
i] = dim[
i] + lb[
i] - 1;
2888 if (lowerIndx[i] > upperIndx[i])
2890 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2891 errmsg(
"upper bound cannot be less than lower bound")));
2906 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2907 errmsg(
"source array too small")));
2919 elmlen, elmbyval, elmalign);
2921 olddatasize =
ARR_SIZE(array) - oldoverheadlen;
2931 lowerIndx, upperIndx,
2932 elmlen, elmbyval, elmalign);
2933 lenbefore = lenafter = 0;
2934 itemsbefore = itemsafter = nolditems = 0;
2943 int oldub = oldlb +
ARR_DIMS(array)[0] - 1;
2944 int slicelb =
Max(oldlb, lowerIndx[0]);
2945 int sliceub =
Min(oldub, upperIndx[0]);
2950 itemsbefore =
Min(slicelb, oldub + 1) - oldlb;
2953 elmlen, elmbyval, elmalign);
2955 if (slicelb > sliceub)
2962 nolditems = sliceub - slicelb + 1;
2964 itemsbefore, oldarraybitmap,
2966 elmlen, elmbyval, elmalign);
2969 itemsafter = oldub + 1 -
Max(sliceub + 1, oldlb);
2970 lenafter = olddatasize - lenbefore - olditemsize;
2973 newsize = overheadlen + olddatasize - olditemsize + newitemsize;
2977 newarray->
ndim = ndim;
2978 newarray->
dataoffset = newhasnulls ? overheadlen : 0;
2980 memcpy(
ARR_DIMS(newarray), dim, ndim *
sizeof(
int));
2981 memcpy(
ARR_LBOUND(newarray), lb, ndim *
sizeof(
int));
2991 lowerIndx, upperIndx,
2992 elmlen, elmbyval, elmalign);
2997 memcpy((
char *) newarray + overheadlen,
2998 (
char *) array + oldoverheadlen,
3000 memcpy((
char *) newarray + overheadlen + lenbefore,
3003 memcpy((
char *) newarray + overheadlen + lenbefore + newitemsize,
3004 (
char *) array + oldoverheadlen + lenbefore + olditemsize,
3013 MemSet(newnullbitmap, 0, (nitems + 7) / 8);
3021 oldnullbitmap, itemsbefore + nolditems,
3038 int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign,
3042 arraytyplen, elmlen, elmbyval, elmalign,
3055 Datum dataValue,
bool isNull,
3056 int arraytyplen,
int elmlen,
bool elmbyval,
char elmalign)
3062 elmlen, elmbyval, elmalign));
3119 if (fcinfo->
nargs < 1)
3153 inp_typlen = inp_extra->
typlen;
3154 inp_typbyval = inp_extra->
typbyval;
3155 inp_typalign = inp_extra->
typalign;
3165 typlen = ret_extra->
typlen;
3171 nulls = (
bool *)
palloc(nitems *
sizeof(
bool));
3177 for (i = 0; i < nitems; i++)
3183 inp_typlen, inp_typbyval, inp_typalign);
3192 for (j = 0; j < fcinfo->
nargs; j++)
3224 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3225 errmsg(
"array size exceeds the maximum allowed (%d)",
3234 nbytes += dataoffset;
3243 result->
ndim = ndim;
3253 values, nulls, nitems,
3254 typlen, typbyval, typalign,
3282 int elmlen,
bool elmbyval,
char elmalign)
3291 elmtype, elmlen, elmbyval, elmalign);
3319 Oid elmtype,
int elmlen,
bool elmbyval,
char elmalign)
3330 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3331 errmsg(
"invalid number of dimensions: %d", ndims)));
3334 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3335 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
3347 for (i = 0; i < nelems; i++)
3349 if (nulls && nulls[i])
3362 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3363 errmsg(
"array size exceeds the maximum allowed (%d)",
3371 nbytes += dataoffset;
3380 result->
ndim = ndims;
3383 memcpy(
ARR_DIMS(result), dims, ndims *
sizeof(
int));
3384 memcpy(
ARR_LBOUND(result), lbs, ndims *
sizeof(
int));
3387 elems, nulls, nelems,
3388 elmlen, elmbyval, elmalign,
3451 int elmlen,
bool elmbyval,
char elmalign,
3452 Datum **elemsp,
bool **nullsp,
int *nelemsp)
3467 *nullsp = nulls = (
bool *)
palloc0(nelems *
sizeof(
bool));
3476 for (i = 0; i < nelems; i++)
3479 if (bitmap && (*bitmap & bitmask) == 0)
3486 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3487 errmsg(
"null array element not allowed in this context")));
3500 if (bitmask == 0x100)
3533 if (*bitmap != 0xFF)
3543 if ((*bitmap & bitmask) == 0)
3588 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3589 errmsg(
"cannot compare arrays of different element types")));
3592 if (ndims1 != ndims2 ||
3593 memcmp(dims1, dims2, ndims1 *
sizeof(
int)) != 0 ||
3594 memcmp(lbs1, lbs2, ndims1 *
sizeof(
int)) != 0)
3605 if (typentry ==
NULL ||
3606 typentry->
type_id != element_type)
3612 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
3613 errmsg(
"could not identify an equality operator for type %s",
3615 fcinfo->flinfo->fn_extra = (
void *) typentry;
3617 typlen = typentry->
typlen;
3632 for (i = 0; i < nitems; i++)
3642 typlen, typbyval, typalign);
3644 typlen, typbyval, typalign);
3649 if (isnull1 && isnull2)
3651 if (isnull1 || isnull2)
3660 locfcinfo.
arg[0] = elt1;
3661 locfcinfo.
arg[1] = elt2;
3664 locfcinfo.
isnull =
false;
3759 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3760 errmsg(
"cannot compare arrays of different element types")));
3769 if (typentry ==
NULL ||
3770 typentry->
type_id != element_type)
3776 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
3777 errmsg(
"could not identify a comparison function for type %s",
3781 typlen = typentry->
typlen;
3792 min_nitems =
Min(nitems1, nitems2);
3796 for (i = 0; i < min_nitems; i++)
3805 elt1 =
array_iter_next(&it1, &isnull1, i, typlen, typbyval, typalign);
3806 elt2 =
array_iter_next(&it2, &isnull2, i, typlen, typbyval, typalign);
3811 if (isnull1 && isnull2)
3827 locfcinfo.
arg[0] = elt1;
3828 locfcinfo.
arg[1] = elt2;
3831 locfcinfo.
isnull =
false;
3859 if (nitems1 != nitems2)
3860 result = (nitems1 < nitems2) ? -1 : 1;
3861 else if (ndims1 != ndims2)
3862 result = (ndims1 < ndims2) ? -1 : 1;
3865 for (i = 0; i < ndims1; i++)
3867 if (dims1[i] != dims2[i])
3869 result = (dims1[
i] < dims2[
i]) ? -1 : 1;
3878 for (i = 0; i < ndims1; i++)
3880 if (lbound1[i] != lbound2[i])
3882 result = (lbound1[
i] < lbound2[
i]) ? -1 : 1;
3928 if (typentry ==
NULL ||
3929 typentry->
type_id != element_type)
3935 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
3936 errmsg(
"could not identify a hash function for type %s",
3938 fcinfo->flinfo->fn_extra = (
void *) typentry;
3940 typlen = typentry->
typlen;
3954 for (i = 0; i < nitems; i++)
3971 locfcinfo.
arg[0] = elt;
3973 locfcinfo.
isnull =
false;
3988 result = (result << 5) - result + elthash;
4014 bool matchall,
void **fn_extra)
4016 bool result = matchall;
4033 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4034 errmsg(
"cannot compare arrays of different element types")));
4043 if (typentry ==
NULL ||
4044 typentry->
type_id != element_type)
4050 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
4051 errmsg(
"could not identify an equality operator for type %s",
4053 *fn_extra = (
void *) typentry;
4055 typlen = typentry->
typlen;
4074 element_type, typlen, typbyval, typalign,
4075 &values2, &nulls2, &nelems2);
4087 for (i = 0; i < nelems1; i++)
4093 elt1 =
array_iter_next(&it1, &isnull1, i, typlen, typbyval, typalign);
4110 for (j = 0; j < nelems2; j++)
4112 Datum elt2 = values2[j];
4113 bool isnull2 = nulls2 ? nulls2[j] :
false;
4122 locfcinfo.
arg[0] = elt1;
4123 locfcinfo.
arg[1] = elt2;
4126 locfcinfo.
isnull =
false;
4164 &fcinfo->flinfo->fn_extra);
4182 &fcinfo->flinfo->fn_extra);
4200 &fcinfo->flinfo->fn_extra);
4237 if (slice_ndim < 0 || slice_ndim >
ARR_NDIM(arr))
4238 elog(
ERROR,
"invalid arguments to array_create_iterator");
4243 iterator->
arr = arr;
4349 for (i = 0; i < iterator->
slice_len; i++)
4415 if (nullbitmap ==
NULL)
4417 if (nullbitmap[offset / 8] & (1 << (offset % 8)))
4434 nullbitmap += offset / 8;
4435 bitmask = 1 << (offset % 8);
4437 *nullbitmap &= ~bitmask;
4439 *nullbitmap |= bitmask;
4499 int typlen,
bool typbyval,
char typalign)
4505 if (typlen > 0 && !nullbitmap)
4511 nullbitmap += offset / 8;
4512 bitmask = 1 << (offset % 8);
4514 for (i = 0; i < nitems; i++)
4516 if (*nullbitmap & bitmask)
4522 if (bitmask == 0x100)
4531 for (i = 0; i < nitems; i++)
4547 int typlen,
bool typbyval,
char typalign)
4549 return array_seek(ptr, offset, nullbitmap, nitems,
4550 typlen, typbyval, typalign) - ptr;
4569 char *srcptr,
int offset,
bits8 *nullbitmap,
4570 int typlen,
bool typbyval,
char typalign)
4575 typlen, typbyval, typalign);
4576 memcpy(destptr, srcptr, numbytes);
4599 const bits8 *srcbitmap,
int srcoffset,
4610 destbitmap += destoffset / 8;
4611 destbitmask = 1 << (destoffset % 8);
4612 destbitval = *destbitmap;
4615 srcbitmap += srcoffset / 8;
4616 srcbitmask = 1 << (srcoffset % 8);
4617 srcbitval = *srcbitmap;
4618 while (nitems-- > 0)
4620 if (srcbitval & srcbitmask)
4621 destbitval |= destbitmask;
4623 destbitval &= ~destbitmask;
4625 if (destbitmask == 0x100)
4627 *destbitmap++ = destbitval;
4630 destbitval = *destbitmap;
4633 if (srcbitmask == 0x100)
4638 srcbitval = *srcbitmap;
4641 if (destbitmask != 1)
4642 *destbitmap = destbitval;
4646 while (nitems-- > 0)
4648 destbitval |= destbitmask;
4650 if (destbitmask == 0x100)
4652 *destbitmap++ = destbitval;
4655 destbitval = *destbitmap;
4658 if (destbitmask != 1)
4659 *destbitmap = destbitval;
4670 int ndim,
int *dim,
int *lb,
4672 int typlen,
bool typbyval,
char typalign)
4688 if (typlen > 0 && !arraynullsptr)
4693 ptr =
array_seek(arraydataptr, 0, arraynullsptr, src_offset,
4694 typlen, typbyval, typalign);
4697 for (i = 0; i < ndim; i++)
4704 ptr =
array_seek(ptr, src_offset, arraynullsptr, dist[j],
4705 typlen, typbyval, typalign);
4706 src_offset += dist[j];
4734 bits8 *arraynullsptr,
4755 srcdataptr =
array_seek(arraydataptr, 0, arraynullsptr, src_offset,
4756 typlen, typbyval, typalign);
4760 for (i = 0; i < ndim; i++)
4769 srcdataptr =
array_seek(srcdataptr, src_offset, arraynullsptr,
4771 typlen, typbyval, typalign);
4772 src_offset += dist[j];
4775 srcdataptr, src_offset, arraynullsptr,
4776 typlen, typbyval, typalign);
4779 arraynullsptr, src_offset,
4836 origPtr, 0, origBitmap,
4837 typlen, typbyval, typalign);
4842 orig_offset = dest_offset;
4846 for (i = 0; i < ndim; i++)
4856 origPtr, orig_offset, origBitmap,
4857 typlen, typbyval, typalign);
4862 origBitmap, orig_offset,
4864 dest_offset += dist[j];
4865 orig_offset += dist[j];
4869 srcPtr, src_offset, srcBitmap,
4870 typlen, typbyval, typalign);
4873 srcBitmap, src_offset,
4880 origPtr =
array_seek(origPtr, orig_offset, origBitmap, 1,
4881 typlen, typbyval, typalign);
4886 array_copy(destPtr, orignitems - orig_offset,
4887 origPtr, orig_offset, origBitmap,
4888 typlen, typbyval, typalign);
4891 origBitmap, orig_offset,
4892 orignitems - orig_offset);
4942 astate->
alen = (subcontext ? 64 : 8);
4946 astate->
dnulls = (
bool *)
4968 Datum dvalue,
bool disnull,
4992 astate->
dnulls = (
bool *)
5006 if (astate->
typlen == -1)
5039 ndims = (astate->
nelems > 0) ? 1 : 0;
5040 dims[0] = astate->
nelems;
5129 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5130 errmsg(
"data type %s is not an array type",
5137 "accumArrayResultArr",
5165 Datum dvalue,
bool disnull,
5186 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5187 errmsg(
"cannot accumulate null arrays")));
5207 if (astate->
ndims == 0)
5214 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5215 errmsg(
"cannot accumulate empty arrays")));
5218 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5219 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
5226 astate->
ndims = ndims + 1;
5227 astate->
dims[0] = 0;
5228 memcpy(&astate->
dims[1], dims, ndims *
sizeof(
int));
5230 memcpy(&astate->
lbs[1], lbs, ndims *
sizeof(
int));
5234 while (astate->
abytes <= ndatabytes)
5241 if (astate->
ndims != ndims + 1)
5243 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5244 errmsg(
"cannot accumulate arrays of different dimensionality")));
5245 for (i = 0; i < ndims; i++)
5247 if (astate->
dims[i + 1] != dims[i] || astate->
lbs[i + 1] != lbs[i])
5249 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5250 errmsg(
"cannot accumulate arrays of different dimensionality")));
5257 astate->
nbytes + ndatabytes);
5268 memcpy(astate->
data + astate->
nbytes, data, ndatabytes);
5269 astate->
nbytes += ndatabytes;
5274 int newnitems = astate->
nitems + nitems;
5283 while (astate->
aitems <= newnitems)
5290 else if (newnitems > astate->
aitems)
5301 astate->
nitems += nitems;
5302 astate->
dims[0] += 1;
5331 if (astate->
ndims == 0)
5346 nbytes += dataoffset;
5442 Datum dvalue,
bool disnull,
5452 input_type, rcontext);
5456 input_type, rcontext);
5551 if (reqdim <= 0 || reqdim >
AARR_NDIM(v))
5563 fctx->
lower = lb[reqdim - 1];
5564 fctx->
upper = dimv[reqdim - 1] + lb[reqdim - 1] - 1;
5615 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5616 errmsg(
"dimension array or low bound array cannot be null")));
5634 elog(
ERROR,
"could not determine data type of input");
5655 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5656 errmsg(
"dimension array or low bound array cannot be null")));
5673 elog(
ERROR,
"could not determine data type of input");
5681 Oid elmtype,
int dataoffset)
5687 result->
ndim = ndims;
5690 memcpy(
ARR_DIMS(result), dimv, ndims *
sizeof(
int));
5691 memcpy(
ARR_LBOUND(result), lbsv, ndims *
sizeof(
int));
5717 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5718 errmsg(
"wrong number of array subscripts"),
5719 errdetail(
"Dimension array must be one dimensional.")));
5723 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5724 errmsg(
"wrong range of array subscripts"),
5725 errdetail(
"Lower bound of dimension array must be one.")));
5729 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5730 errmsg(
"dimension values cannot be null")));
5737 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5738 errmsg(
"invalid number of dimensions: %d", ndims)));
5741 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5742 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
5749 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5750 errmsg(
"wrong number of array subscripts"),
5751 errdetail(
"Dimension array must be one dimensional.")));
5755 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5756 errmsg(
"wrong range of array subscripts"),
5757 errdetail(
"Lower bound of dimension array must be one.")));
5761 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5762 errmsg(
"dimension values cannot be null")));
5766 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
5767 errmsg(
"wrong number of array subscripts"),
5768 errdetail(
"Low bound array has different size than dimensions array.")));
5776 for (i = 0; i <
MAXDIM; i++)
5793 if (my_extra ==
NULL)
5811 elmlen = my_extra->
typlen;
5831 totbytes = nbytes * nitems;
5834 if (totbytes / nbytes != nitems ||
5837 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5838 errmsg(
"array size exceeds the maximum allowed (%d)",
5851 for (i = 0; i < nitems; i++)
5860 nbytes = dataoffset;
5863 elmtype, dataoffset);
5886 } array_unnest_fctx;
5889 array_unnest_fctx *fctx;
5915 fctx = (array_unnest_fctx *)
palloc(
sizeof(array_unnest_fctx));
5943 if (fctx->nextelem < fctx->numelems)
5945 int offset = fctx->nextelem++;
5949 fctx->elmlen, fctx->elmbyval, fctx->elmalign);
5971 Datum search,
bool search_isnull,
5972 Datum replace,
bool replace_isnull,
5973 bool remove,
Oid collation,
5994 bool changed =
false;
6011 if (
remove && ndim > 1)
6013 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6014 errmsg(
"removing elements from multidimensional arrays is not supported")));
6021 if (typentry ==
NULL ||
6022 typentry->
type_id != element_type)
6028 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
6029 errmsg(
"could not identify an equality operator for type %s",
6033 typlen = typentry->
typlen;
6046 if (!replace_isnull)
6056 nulls = (
bool *)
palloc(nitems *
sizeof(
bool));
6065 for (i = 0; i < nitems; i++)
6073 if (bitmap && (*bitmap & bitmask) == 0)
6084 else if (!replace_isnull)
6086 values[nresult] = replace;
6095 elt =
fetch_att(arraydataptr, typbyval, typlen);
6102 values[nresult] = elt;
6109 locfcinfo.
arg[0] = elt;
6110 locfcinfo.
arg[1] = search;
6113 locfcinfo.
isnull =
false;
6118 values[nresult] = elt;
6128 values[nresult] = replace;
6129 isNull = replace_isnull;
6137 nulls[nresult] = isNull;
6148 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
6149 errmsg(
"array size exceeds the maximum allowed (%d)",
6159 if (bitmask == 0x100)
6189 nbytes += dataoffset;
6198 result->
ndim = ndim;
6212 values, nulls, nresult,
6213 typlen, typbyval, typalign,
6239 search, search_isnull,
6263 search, search_isnull,
6264 replace, replace_isnull,
6290 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
6291 errmsg(
"thresholds must be one-dimensional array")));
6295 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6296 errmsg(
"thresholds array must not contain NULLs")));
6307 if (typentry ==
NULL ||
6308 typentry->
type_id != element_type)
6314 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
6315 errmsg(
"could not identify a comparison function for type %s",
6317 fcinfo->flinfo->fn_extra = (
void *) typentry;
6324 if (typentry->
typlen > 0)
6326 collation, typentry);
6329 collation, typentry);
6369 while (left < right)
6371 int mid = (left + right) / 2;
6373 if (isnan(thresholds_data[mid]) || op < thresholds_data[mid])
6391 char *thresholds_data;
6392 int typlen = typentry->
typlen;
6393 bool typbyval = typentry->
typbyval;
6410 while (left < right)
6412 int mid = (left + right) / 2;
6416 ptr = thresholds_data + mid * typlen;
6418 locfcinfo.
arg[0] = operand;
6422 locfcinfo.
isnull =
false;
6444 char *thresholds_data;
6445 int typlen = typentry->
typlen;
6446 bool typbyval = typentry->
typbyval;
6447 char typalign = typentry->
typalign;
6460 while (left < right)
6462 int mid = (left + right) / 2;
6468 ptr = thresholds_data;
6469 for (i = left; i < mid; i++)
6475 locfcinfo.
arg[0] = operand;
6479 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)
Datum array_iter_next(array_iter *it, bool *isnull, int i, int elmlen, bool elmbyval, char elmalign)
static int ArrayCastAndSet(Datum src, int typlen, bool typbyval, char typalign, char *dest)
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)
#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)
MemoryContext MemoryContextSwitchTo(MemoryContext context)
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 array_iter_setup(array_iter *it, AnyArrayType *a)
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)