102 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
103 errmsg(
"could not determine input data type")));
107 (
errcode(ERRCODE_DATATYPE_MISMATCH),
108 errmsg(
"input data type is not an array")));
151 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
152 errmsg(
"integer out of range")));
154 else if (eah->
ndims == 0)
158 (
errcode(ERRCODE_DATA_EXCEPTION),
159 errmsg(
"argument must be empty or one-dimensional array")));
165 1, &indx, newelem, isNull,
233 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
234 errmsg(
"integer out of range")));
236 else if (eah->
ndims == 0)
243 (
errcode(ERRCODE_DATA_EXCEPTION),
244 errmsg(
"argument must be empty or one-dimensional array")));
250 1, &indx, newelem, isNull,
353 if (element_type1 != element_type2)
355 (
errcode(ERRCODE_DATATYPE_MISMATCH),
356 errmsg(
"cannot concatenate incompatible arrays"),
357 errdetail(
"Arrays with element types %s and %s are not "
358 "compatible for concatenation.",
363 element_type = element_type1;
383 if (ndims1 == 0 && ndims2 > 0)
390 if (ndims1 != ndims2 &&
391 ndims1 != ndims2 - 1 &&
392 ndims1 != ndims2 + 1)
394 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
395 errmsg(
"cannot concatenate incompatible arrays"),
396 errdetail(
"Arrays of %d and %d dimensions are not "
397 "compatible for concatenation.",
414 if (ndims1 == ndims2)
421 dims = (
int *)
palloc(ndims *
sizeof(
int));
422 lbs = (
int *)
palloc(ndims *
sizeof(
int));
424 dims[0] = dims1[0] + dims2[0];
427 for (
i = 1;
i < ndims;
i++)
429 if (dims1[
i] != dims2[
i] || lbs1[
i] != lbs2[
i])
431 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
432 errmsg(
"cannot concatenate incompatible arrays"),
433 errdetail(
"Arrays with differing element dimensions are "
434 "not compatible for concatenation.")));
440 else if (ndims1 == ndims2 - 1)
447 dims = (
int *)
palloc(ndims *
sizeof(
int));
448 lbs = (
int *)
palloc(ndims *
sizeof(
int));
449 memcpy(dims, dims2, ndims *
sizeof(
int));
450 memcpy(lbs, lbs2, ndims *
sizeof(
int));
456 for (
i = 0;
i < ndims1;
i++)
458 if (dims1[
i] != dims[
i + 1] || lbs1[
i] != lbs[
i + 1])
460 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
461 errmsg(
"cannot concatenate incompatible arrays"),
462 errdetail(
"Arrays with differing dimensions are not "
463 "compatible for concatenation.")));
475 dims = (
int *)
palloc(ndims *
sizeof(
int));
476 lbs = (
int *)
palloc(ndims *
sizeof(
int));
477 memcpy(dims, dims1, ndims *
sizeof(
int));
478 memcpy(lbs, lbs1, ndims *
sizeof(
int));
484 for (
i = 0;
i < ndims2;
i++)
486 if (dims2[
i] != dims[
i + 1] || lbs2[
i] != lbs[
i + 1])
488 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
489 errmsg(
"cannot concatenate incompatible arrays"),
490 errdetail(
"Arrays with differing dimensions are not "
491 "compatible for concatenation.")));
500 ndatabytes = ndatabytes1 + ndatabytes2;
504 nbytes = ndatabytes + dataoffset;
513 result->
ndim = ndims;
516 memcpy(
ARR_DIMS(result), dims, ndims *
sizeof(
int));
517 memcpy(
ARR_LBOUND(result), lbs, ndims *
sizeof(
int));
520 memcpy(
ARR_DATA_PTR(result) + ndatabytes1, dat2, ndatabytes2);
549 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
550 errmsg(
"could not determine input data type")));
561 elog(
ERROR,
"array_agg_transfn called in non-aggregate context");
594 elog(
ERROR,
"aggregate function called in non-aggregate context");
614 false, state2->
alen);
636 else if (state2->
nelems > 0)
645 if (state1->
alen < reqsize)
652 state1->
alen *
sizeof(
bool));
668 sizeof(
bool) * state2->
nelems);
749 fcinfo->flinfo->fn_extra = iodata;
782 elog(
ERROR,
"aggregate function called in non-aggregate context");
815 memcpy(result->
dnulls, temp,
sizeof(
bool) * nelems);
840 fcinfo->flinfo->fn_extra = iodata;
843 for (
int i = 0;
i < nelems;
i++)
855 if (itemlen < 0 || itemlen > (
buf.len -
buf.cursor))
857 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
858 errmsg(
"insufficient data left in message")));
867 buf.cursor += itemlen;
898 dims[0] =
state->nelems;
926 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
927 errmsg(
"could not determine input data type")));
938 elog(
ERROR,
"array_agg_array_transfn called in non-aggregate context");
970 elog(
ERROR,
"aggregate function called in non-aggregate context");
999 int size = (state2->
aitems + 7) / 8;
1010 memcpy(state1->
dims, state2->
dims,
sizeof(state2->
dims));
1011 memcpy(state1->
lbs, state2->
lbs,
sizeof(state2->
lbs));
1021 else if (state2->
nitems > 0)
1035 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1036 errmsg(
"cannot accumulate arrays of different dimensionality")));
1039 for (
i = 1;
i < state1->
ndims;
i++)
1043 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1044 errmsg(
"cannot accumulate arrays of different dimensionality")));
1054 if (state1->
abytes < reqsize)
1077 else if (newnitems > state1->
aitems)
1094 state1->
dims[0] += state2->
dims[0];
1146 if (
state->nullbitmap)
1205 while (result->
abytes < nbytes)
1212 memcpy(result->
data, temp, nbytes);
1224 int size = (result->
aitems + 7) / 8;
1241 memcpy(result->
dims, temp,
sizeof(result->
dims));
1245 memcpy(result->
lbs, temp,
sizeof(result->
lbs));
1310 Datum searched_element,
1332 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1333 errmsg(
"searching for elements in multidimensional arrays is not supported")));
1344 searched_element = (
Datum) 0;
1350 null_search =
false;
1361 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1362 errmsg(
"initial position must not be null")));
1375 if (my_extra == NULL)
1394 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1395 errmsg(
"could not identify an equality operator for type %s",
1410 if (position < position_min)
1417 if (isnull || null_search)
1419 if (isnull && null_search)
1430 searched_element,
value)))
1465 Datum searched_element,
1486 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1487 errmsg(
"searching for elements in multidimensional arrays is not supported")));
1500 searched_element = (
Datum) 0;
1506 null_search =
false;
1518 if (my_extra == NULL)
1537 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1538 errmsg(
"could not identify an equality operator for type %s",
1559 if (isnull || null_search)
1561 if (isnull && null_search)
1571 searched_element,
value)))
1621 elmlen = typentry->
typlen;
1626 if (ndim < 1 || dims[0] < 1 || n < 1)
1630 &elms, &nuls, &nelm);
1645 for (
int i = 0;
i < n;
i++)
1649 bool *jnuls = nuls +
j;
1652 for (
int k = 0; k < nelm; k++)
1665 memcpy(rdims, dims, ndim *
sizeof(
int));
1666 memcpy(rlbs, lbs, ndim *
sizeof(
int));
1672 elmtyp, elmlen, elmbyval, elmalign);
1703 if (typentry == NULL || typentry->
type_id != elmtyp)
1706 fcinfo->flinfo->fn_extra = typentry;
1732 if (n < 0 || n > nitem)
1734 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1735 errmsg(
"sample size must be between 0 and %d", nitem)));
1739 if (typentry == NULL || typentry->
type_id != elmtyp)
1742 fcinfo->flinfo->fn_extra = typentry;
1782 elmlen = typentry->
typlen;
1787 &elms, &nuls, &nelm);
1795 for (
int i = 0;
i < nitem / 2;
i++)
1797 int j = (nitem -
i - 1) * nelm;
1799 bool *jnuls = nuls +
j;
1802 for (
int k = 0; k < nelm; k++)
1815 memcpy(rdims, dims, ndim *
sizeof(
int));
1816 memcpy(rlbs, lbs, ndim *
sizeof(
int));
1820 elmtyp, elmlen, elmbyval, elmalign);
1851 if (typentry == NULL || typentry->
type_id != elmtyp)
1854 fcinfo->flinfo->fn_extra = (
void *) typentry;
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
#define PG_GETARG_ARRAYTYPE_P(n)
#define ARR_NULLBITMAP(a)
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
#define PG_RETURN_ARRAYTYPE_P(x)
#define ARR_OVERHEAD_NONULLS(ndims)
#define ARR_DATA_OFFSET(a)
#define PG_GETARG_EXPANDED_ARRAYX(n, metacache)
Datum array_sample(PG_FUNCTION_ARGS)
struct DeserialIOData DeserialIOData
Datum array_prepend(PG_FUNCTION_ARGS)
Datum array_agg_deserialize(PG_FUNCTION_ARGS)
Datum array_positions(PG_FUNCTION_ARGS)
static Datum array_position_common(FunctionCallInfo fcinfo)
Datum array_position(PG_FUNCTION_ARGS)
static ExpandedArrayHeader * fetch_array_arg_replace_nulls(FunctionCallInfo fcinfo, int argno)
struct SerialIOData SerialIOData
Datum array_agg_combine(PG_FUNCTION_ARGS)
Datum array_reverse(PG_FUNCTION_ARGS)
Datum array_append(PG_FUNCTION_ARGS)
Datum array_agg_array_combine(PG_FUNCTION_ARGS)
Datum array_agg_serialize(PG_FUNCTION_ARGS)
Datum array_agg_array_deserialize(PG_FUNCTION_ARGS)
Datum array_append_support(PG_FUNCTION_ARGS)
Datum array_agg_finalfn(PG_FUNCTION_ARGS)
Datum array_agg_array_transfn(PG_FUNCTION_ARGS)
Datum array_position_start(PG_FUNCTION_ARGS)
Datum array_shuffle(PG_FUNCTION_ARGS)
Datum array_cat(PG_FUNCTION_ARGS)
static ArrayType * array_reverse_n(ArrayType *array, Oid elmtyp, TypeCacheEntry *typentry)
static ArrayType * array_shuffle_n(ArrayType *array, int n, bool keep_lb, Oid elmtyp, TypeCacheEntry *typentry)
Datum array_agg_transfn(PG_FUNCTION_ARGS)
Datum array_agg_array_finalfn(PG_FUNCTION_ARGS)
Datum array_agg_array_serialize(PG_FUNCTION_ARGS)
Datum array_prepend_support(PG_FUNCTION_ARGS)
bool array_contains_nulls(ArrayType *array)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ExpandedArrayHeader * construct_empty_expanded_array(Oid element_type, MemoryContext parentcontext, ArrayMetaState *metacache)
bool array_iterate(ArrayIterator iterator, Datum *value, bool *isnull)
void array_free_iterator(ArrayIterator iterator)
ArrayType * construct_empty_array(Oid elmtype)
Datum makeArrayResultArr(ArrayBuildStateArr *astate, MemoryContext rcontext, bool release)
Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)
ArrayBuildStateArr * initArrayResultArr(Oid array_type, Oid element_type, MemoryContext rcontext, bool subcontext)
ArrayBuildStateArr * accumArrayResultArr(ArrayBuildStateArr *astate, Datum dvalue, bool disnull, Oid array_type, MemoryContext rcontext)
ArrayIterator array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
ArrayBuildState * initArrayResultWithSize(Oid element_type, MemoryContext rcontext, bool subcontext, int initsize)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
int ArrayGetNItems(int ndim, const int *dims)
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
#define OidIsValid(objectId)
Datum datumCopy(Datum value, bool typByVal, int typLen)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
static Datum EOHPGetRWDatum(const struct ExpandedObjectHeader *eohptr)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_BYTEA_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_DATUM(n)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
Assert(PointerIsAligned(start, uint64))
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
if(TABLE==NULL||TABLE_index==NULL)
void getTypeBinaryOutputInfo(Oid type, Oid *typSend, bool *typIsVarlena)
Oid get_element_type(Oid typid)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
void getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typIOParam)
void * MemoryContextAlloc(MemoryContext context, Size size)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
#define IsA(nodeptr, _type_)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static uint32 pg_nextpower2_32(uint32 num)
uint64 pg_prng_uint64_range(pg_prng_state *state, uint64 rmin, uint64 rmax)
pg_prng_state pg_global_prng_state
static bool DatumGetBool(Datum X)
static Datum Int32GetDatum(int32 X)
static void initReadOnlyStringInfo(StringInfo str, char *data, int len)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define TYPECACHE_EQ_OPR_FINFO
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)