MCPcopy Create free account
hub / github.com/apache/cloudberry / array_append

Function array_append

src/backend/utils/adt/array_userfuncs.c:121–167  ·  view source on GitHub ↗

----------------------------------------------------------------------------- * array_append : * push an element onto the end of a one-dimensional array *---------------------------------------------------------------------------- */

Source from the content-addressed store, hash-verified

119 *----------------------------------------------------------------------------
120 */
121Datum
122array_append(PG_FUNCTION_ARGS)
123{
124 ExpandedArrayHeader *eah;
125 Datum newelem;
126 bool isNull;
127 Datum result;
128 int *dimv,
129 *lb;
130 int indx;
131 ArrayMetaState *my_extra;
132
133 eah = fetch_array_arg_replace_nulls(fcinfo, 0);
134 isNull = PG_ARGISNULL(1);
135 if (isNull)
136 newelem = (Datum) 0;
137 else
138 newelem = PG_GETARG_DATUM(1);
139
140 if (eah->ndims == 1)
141 {
142 /* append newelem */
143 lb = eah->lbound;
144 dimv = eah->dims;
145
146 /* index of added elem is at lb[0] + (dimv[0] - 1) + 1 */
147 if (pg_add_s32_overflow(lb[0], dimv[0], &indx))
148 ereport(ERROR,
149 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
150 errmsg("integer out of range")));
151 }
152 else if (eah->ndims == 0)
153 indx = 1;
154 else
155 ereport(ERROR,
156 (errcode(ERRCODE_DATA_EXCEPTION),
157 errmsg("argument must be empty or one-dimensional array")));
158
159 /* Perform element insertion */
160 my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
161
162 result = array_set_element(EOHPGetRWDatum(&eah->hdr),
163 1, &indx, newelem, isNull,
164 -1, my_extra->typlen, my_extra->typbyval, my_extra->typalign);
165
166 PG_RETURN_DATUM(result);
167}
168
169/*-----------------------------------------------------------------------------
170 * array_prepend :

Callers

nothing calls this directly

Calls 5

pg_add_s32_overflowFunction · 0.85
array_set_elementFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected