101 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
102 errmsg(
"could not determine input data type")));
106 (
errcode(ERRCODE_DATATYPE_MISMATCH),
107 errmsg(
"input data type is not an array")));
150 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
151 errmsg(
"integer out of range")));
153 else if (eah->
ndims == 0)
157 (
errcode(ERRCODE_DATA_EXCEPTION),
158 errmsg(
"argument must be empty or one-dimensional array")));
164 1, &indx, newelem, isNull,
202 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
203 errmsg(
"integer out of range")));
205 else if (eah->
ndims == 0)
212 (
errcode(ERRCODE_DATA_EXCEPTION),
213 errmsg(
"argument must be empty or one-dimensional array")));
219 1, &indx, newelem, isNull,
292 if (element_type1 != element_type2)
294 (
errcode(ERRCODE_DATATYPE_MISMATCH),
295 errmsg(
"cannot concatenate incompatible arrays"),
296 errdetail(
"Arrays with element types %s and %s are not "
297 "compatible for concatenation.",
302 element_type = element_type1;
322 if (ndims1 == 0 && ndims2 > 0)
329 if (ndims1 != ndims2 &&
330 ndims1 != ndims2 - 1 &&
331 ndims1 != ndims2 + 1)
333 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
334 errmsg(
"cannot concatenate incompatible arrays"),
335 errdetail(
"Arrays of %d and %d dimensions are not "
336 "compatible for concatenation.",
353 if (ndims1 == ndims2)
360 dims = (
int *)
palloc(ndims *
sizeof(
int));
361 lbs = (
int *)
palloc(ndims *
sizeof(
int));
363 dims[0] = dims1[0] + dims2[0];
366 for (
i = 1;
i < ndims;
i++)
368 if (dims1[
i] != dims2[
i] || lbs1[
i] != lbs2[
i])
370 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
371 errmsg(
"cannot concatenate incompatible arrays"),
372 errdetail(
"Arrays with differing element dimensions are "
373 "not compatible for concatenation.")));
379 else if (ndims1 == ndims2 - 1)
386 dims = (
int *)
palloc(ndims *
sizeof(
int));
387 lbs = (
int *)
palloc(ndims *
sizeof(
int));
388 memcpy(dims, dims2, ndims *
sizeof(
int));
389 memcpy(lbs, lbs2, ndims *
sizeof(
int));
395 for (
i = 0;
i < ndims1;
i++)
397 if (dims1[
i] != dims[
i + 1] || lbs1[
i] != lbs[
i + 1])
399 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
400 errmsg(
"cannot concatenate incompatible arrays"),
401 errdetail(
"Arrays with differing dimensions are not "
402 "compatible for concatenation.")));
414 dims = (
int *)
palloc(ndims *
sizeof(
int));
415 lbs = (
int *)
palloc(ndims *
sizeof(
int));
416 memcpy(dims, dims1, ndims *
sizeof(
int));
417 memcpy(lbs, lbs1, ndims *
sizeof(
int));
423 for (
i = 0;
i < ndims2;
i++)
425 if (dims2[
i] != dims[
i + 1] || lbs2[
i] != lbs[
i + 1])
427 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
428 errmsg(
"cannot concatenate incompatible arrays"),
429 errdetail(
"Arrays with differing dimensions are not "
430 "compatible for concatenation.")));
439 ndatabytes = ndatabytes1 + ndatabytes2;
443 nbytes = ndatabytes + dataoffset;
452 result->
ndim = ndims;
455 memcpy(
ARR_DIMS(result), dims, ndims *
sizeof(
int));
456 memcpy(
ARR_LBOUND(result), lbs, ndims *
sizeof(
int));
459 memcpy(
ARR_DATA_PTR(result) + ndatabytes1, dat2, ndatabytes2);
488 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
489 errmsg(
"could not determine input data type")));
500 elog(
ERROR,
"array_agg_transfn called in non-aggregate context");
533 elog(
ERROR,
"aggregate function called in non-aggregate context");
553 false, state2->
alen);
575 else if (state2->
nelems > 0)
584 if (state1->
alen < reqsize)
591 state1->
alen *
sizeof(
bool));
607 sizeof(
bool) * state2->
nelems);
688 fcinfo->flinfo->fn_extra = iodata;
721 elog(
ERROR,
"aggregate function called in non-aggregate context");
754 memcpy(result->
dnulls, temp,
sizeof(
bool) * nelems);
779 fcinfo->flinfo->fn_extra = iodata;
782 for (
int i = 0;
i < nelems;
i++)
794 if (itemlen < 0 || itemlen > (
buf.len -
buf.cursor))
796 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
797 errmsg(
"insufficient data left in message")));
806 buf.cursor += itemlen;
837 dims[0] =
state->nelems;
865 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
866 errmsg(
"could not determine input data type")));
877 elog(
ERROR,
"array_agg_array_transfn called in non-aggregate context");
909 elog(
ERROR,
"aggregate function called in non-aggregate context");
949 memcpy(state1->
dims, state2->
dims,
sizeof(state2->
dims));
950 memcpy(state1->
lbs, state2->
lbs,
sizeof(state2->
lbs));
960 else if (state2->
nitems > 0)
974 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
975 errmsg(
"cannot accumulate arrays of different dimensionality")));
982 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
983 errmsg(
"cannot accumulate arrays of different dimensionality")));
993 if (state1->
abytes < reqsize)
1016 else if (newnitems > state1->
aitems)
1033 state1->
dims[0] += state2->
dims[0];
1085 if (
state->nullbitmap)
1144 while (result->
abytes < nbytes)
1151 memcpy(result->
data, temp, nbytes);
1180 memcpy(result->
dims, temp,
sizeof(result->
dims));
1184 memcpy(result->
lbs, temp,
sizeof(result->
lbs));
1249 Datum searched_element,
1271 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1272 errmsg(
"searching for elements in multidimensional arrays is not supported")));
1283 searched_element = (
Datum) 0;
1289 null_search =
false;
1300 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1301 errmsg(
"initial position must not be null")));
1314 if (my_extra == NULL)
1333 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1334 errmsg(
"could not identify an equality operator for type %s",
1349 if (position < position_min)
1356 if (isnull || null_search)
1358 if (isnull && null_search)
1369 searched_element,
value)))
1404 Datum searched_element,
1425 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1426 errmsg(
"searching for elements in multidimensional arrays is not supported")));
1439 searched_element = (
Datum) 0;
1445 null_search =
false;
1457 if (my_extra == NULL)
1476 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1477 errmsg(
"could not identify an equality operator for type %s",
1498 if (isnull || null_search)
1500 if (isnull && null_search)
1510 searched_element,
value)))
1560 elmlen = typentry->
typlen;
1565 if (ndim < 1 || dims[0] < 1 || n < 1)
1569 &elms, &nuls, &nelm);
1584 for (
int i = 0;
i < n;
i++)
1588 bool *jnuls = nuls +
j;
1591 for (
int k = 0; k < nelm; k++)
1604 memcpy(rdims, dims, ndim *
sizeof(
int));
1605 memcpy(rlbs, lbs, ndim *
sizeof(
int));
1611 elmtyp, elmlen, elmbyval, elmalign);
1642 if (typentry == NULL || typentry->
type_id != elmtyp)
1645 fcinfo->flinfo->fn_extra = typentry;
1671 if (n < 0 || n > nitem)
1673 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1674 errmsg(
"sample size must be between 0 and %d", nitem)));
1678 if (typentry == NULL || typentry->
type_id != elmtyp)
1681 fcinfo->flinfo->fn_extra = typentry;
1721 elmlen = typentry->
typlen;
1726 &elms, &nuls, &nelm);
1734 for (
int i = 0;
i < nitem / 2;
i++)
1736 int j = (nitem -
i - 1) * nelm;
1738 bool *jnuls = nuls +
j;
1741 for (
int k = 0; k < nelm; k++)
1754 memcpy(rdims, dims, ndim *
sizeof(
int));
1755 memcpy(rlbs, lbs, ndim *
sizeof(
int));
1759 elmtyp, elmlen, elmbyval, elmalign);
1790 if (typentry == NULL || typentry->
type_id != elmtyp)
1793 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)
static ArrayType * array_shuffle_n(ArrayType *array, int n, bool keep_lb, Oid elmtyp, TypeCacheEntry *typentry)
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)
struct SerialIOData SerialIOData
Datum array_agg_combine(PG_FUNCTION_ARGS)
Datum array_reverse(PG_FUNCTION_ARGS)
static ArrayType * array_reverse_n(ArrayType *array, Oid elmtyp, TypeCacheEntry *typentry)
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_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)
static ExpandedArrayHeader * fetch_array_arg_replace_nulls(FunctionCallInfo fcinfo, int argno)
Datum array_cat(PG_FUNCTION_ARGS)
Datum array_agg_transfn(PG_FUNCTION_ARGS)
Datum array_agg_array_finalfn(PG_FUNCTION_ARGS)
Datum array_agg_array_serialize(PG_FUNCTION_ARGS)
bool array_contains_nulls(ArrayType *array)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
bool array_iterate(ArrayIterator iterator, Datum *value, bool *isnull)
ArrayBuildState * initArrayResultWithSize(Oid element_type, MemoryContext rcontext, bool subcontext, int initsize)
void array_free_iterator(ArrayIterator iterator)
ArrayBuildStateArr * initArrayResultArr(Oid array_type, Oid element_type, MemoryContext rcontext, bool subcontext)
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)
ArrayIterator array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
ArrayType * construct_empty_array(Oid elmtype)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
ArrayBuildStateArr * accumArrayResultArr(ArrayBuildStateArr *astate, Datum dvalue, bool disnull, Oid array_type, MemoryContext rcontext)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
ExpandedArrayHeader * construct_empty_expanded_array(Oid element_type, MemoryContext parentcontext, ArrayMetaState *metacache)
int ArrayGetNItems(int ndim, const int *dims)
void ArrayCheckBounds(int ndim, const int *dims, const int *lb)
#define Assert(condition)
#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)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
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()
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 pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void * repalloc(void *pointer, Size size)
void * MemoryContextAlloc(MemoryContext context, Size size)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
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)
MemoryContextSwitchTo(old_ctx)
static pg_noinline void Size size
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)