100 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
101 errmsg(
"could not determine input data type")));
105 (
errcode(ERRCODE_DATATYPE_MISMATCH),
106 errmsg(
"input data type is not an array")));
149 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
150 errmsg(
"integer out of range")));
152 else if (eah->
ndims == 0)
156 (
errcode(ERRCODE_DATA_EXCEPTION),
157 errmsg(
"argument must be empty or one-dimensional array")));
163 1, &indx, newelem, isNull,
201 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
202 errmsg(
"integer out of range")));
204 else if (eah->
ndims == 0)
211 (
errcode(ERRCODE_DATA_EXCEPTION),
212 errmsg(
"argument must be empty or one-dimensional array")));
218 1, &indx, newelem, isNull,
291 if (element_type1 != element_type2)
293 (
errcode(ERRCODE_DATATYPE_MISMATCH),
294 errmsg(
"cannot concatenate incompatible arrays"),
295 errdetail(
"Arrays with element types %s and %s are not "
296 "compatible for concatenation.",
301 element_type = element_type1;
321 if (ndims1 == 0 && ndims2 > 0)
328 if (ndims1 != ndims2 &&
329 ndims1 != ndims2 - 1 &&
330 ndims1 != ndims2 + 1)
332 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
333 errmsg(
"cannot concatenate incompatible arrays"),
334 errdetail(
"Arrays of %d and %d dimensions are not "
335 "compatible for concatenation.",
352 if (ndims1 == ndims2)
359 dims = (
int *)
palloc(ndims *
sizeof(
int));
360 lbs = (
int *)
palloc(ndims *
sizeof(
int));
362 dims[0] = dims1[0] + dims2[0];
365 for (
i = 1;
i < ndims;
i++)
367 if (dims1[
i] != dims2[
i] || lbs1[
i] != lbs2[
i])
369 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
370 errmsg(
"cannot concatenate incompatible arrays"),
371 errdetail(
"Arrays with differing element dimensions are "
372 "not compatible for concatenation.")));
378 else if (ndims1 == ndims2 - 1)
385 dims = (
int *)
palloc(ndims *
sizeof(
int));
386 lbs = (
int *)
palloc(ndims *
sizeof(
int));
387 memcpy(dims, dims2, ndims *
sizeof(
int));
388 memcpy(lbs, lbs2, ndims *
sizeof(
int));
394 for (
i = 0;
i < ndims1;
i++)
396 if (dims1[
i] != dims[
i + 1] || lbs1[
i] != lbs[
i + 1])
398 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
399 errmsg(
"cannot concatenate incompatible arrays"),
400 errdetail(
"Arrays with differing dimensions are not "
401 "compatible for concatenation.")));
413 dims = (
int *)
palloc(ndims *
sizeof(
int));
414 lbs = (
int *)
palloc(ndims *
sizeof(
int));
415 memcpy(dims, dims1, ndims *
sizeof(
int));
416 memcpy(lbs, lbs1, ndims *
sizeof(
int));
422 for (
i = 0;
i < ndims2;
i++)
424 if (dims2[
i] != dims[
i + 1] || lbs2[
i] != lbs[
i + 1])
426 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
427 errmsg(
"cannot concatenate incompatible arrays"),
428 errdetail(
"Arrays with differing dimensions are not "
429 "compatible for concatenation.")));
438 ndatabytes = ndatabytes1 + ndatabytes2;
442 nbytes = ndatabytes + dataoffset;
451 result->
ndim = ndims;
454 memcpy(
ARR_DIMS(result), dims, ndims *
sizeof(
int));
455 memcpy(
ARR_LBOUND(result), lbs, ndims *
sizeof(
int));
458 memcpy(
ARR_DATA_PTR(result) + ndatabytes1, dat2, ndatabytes2);
487 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
488 errmsg(
"could not determine input data type")));
499 elog(
ERROR,
"array_agg_transfn called in non-aggregate context");
532 elog(
ERROR,
"aggregate function called in non-aggregate context");
552 false, state2->
alen);
574 else if (state2->
nelems > 0)
583 if (state1->
alen < reqsize)
590 state1->
alen *
sizeof(
bool));
606 sizeof(
bool) * state2->
nelems);
687 fcinfo->flinfo->fn_extra = (
void *) iodata;
720 elog(
ERROR,
"aggregate function called in non-aggregate context");
754 memcpy(result->
dnulls, temp,
sizeof(
bool) * nelems);
779 fcinfo->flinfo->fn_extra = (
void *) iodata;
782 for (
int i = 0;
i < nelems;
i++)
795 if (itemlen < 0 || itemlen > (
buf.len -
buf.cursor))
797 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
798 errmsg(
"insufficient data left in message")));
807 elem_buf.
maxlen = itemlen + 1;
808 elem_buf.
len = itemlen;
811 buf.cursor += itemlen;
813 csave =
buf.data[
buf.cursor];
814 buf.data[
buf.cursor] =
'\0';
822 buf.data[
buf.cursor] = csave;
848 dims[0] =
state->nelems;
876 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
877 errmsg(
"could not determine input data type")));
888 elog(
ERROR,
"array_agg_array_transfn called in non-aggregate context");
920 elog(
ERROR,
"aggregate function called in non-aggregate context");
949 int size = (state2->
aitems + 7) / 8;
960 memcpy(state1->
dims, state2->
dims,
sizeof(state2->
dims));
961 memcpy(state1->
lbs, state2->
lbs,
sizeof(state2->
lbs));
971 else if (state2->
nitems > 0)
985 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
986 errmsg(
"cannot accumulate arrays of different dimensionality")));
993 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
994 errmsg(
"cannot accumulate arrays of different dimensionality")));
1004 if (state1->
abytes < reqsize)
1027 else if (newnitems > state1->
aitems)
1044 state1->
dims[0] += state2->
dims[0];
1096 if (
state->nullbitmap)
1156 while (result->
abytes < nbytes)
1163 memcpy(result->
data, temp, nbytes);
1175 int size = (result->
aitems + 7) / 8;
1192 memcpy(result->
dims, temp,
sizeof(result->
dims));
1196 memcpy(result->
lbs, temp,
sizeof(result->
lbs));
1262 Datum searched_element,
1285 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1286 errmsg(
"searching for elements in multidimensional arrays is not supported")));
1293 searched_element = (
Datum) 0;
1299 null_search =
false;
1309 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
1310 errmsg(
"initial position must not be null")));
1323 if (my_extra == NULL)
1342 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1343 errmsg(
"could not identify an equality operator for type %s",
1358 if (position < position_min)
1365 if (isnull || null_search)
1367 if (isnull && null_search)
1378 searched_element,
value)))
1413 Datum searched_element,
1437 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1438 errmsg(
"searching for elements in multidimensional arrays is not supported")));
1447 searched_element = (
Datum) 0;
1453 null_search =
false;
1462 if (my_extra == NULL)
1481 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1482 errmsg(
"could not identify an equality operator for type %s",
1503 if (isnull || null_search)
1505 if (isnull && null_search)
1515 searched_element,
value)))
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)
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)
struct SerialIOData SerialIOData
Datum array_agg_combine(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_agg_finalfn(PG_FUNCTION_ARGS)
Datum array_agg_array_transfn(PG_FUNCTION_ARGS)
Datum array_position_start(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)
ArrayBuildStateArr * accumArrayResultArr(ArrayBuildStateArr *astate, Datum dvalue, bool disnull, Oid array_type, MemoryContext rcontext)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
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 OidIsValid(objectId)
Datum datumCopy(Datum value, bool typByVal, int typLen)
elog(ERROR, "%s: %s", p2, msg)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
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 MemoryContext MemoryContextSwitchTo(MemoryContext context)
static uint32 pg_nextpower2_32(uint32 num)
static bool DatumGetBool(Datum X)
static Datum Int32GetDatum(int32 X)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void initStringInfo(StringInfo str)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define TYPECACHE_EQ_OPR_FINFO
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)