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

Function array_set_element

src/backend/utils/adt/arrayfuncs.c:2214–2506  ·  view source on GitHub ↗

* array_set_element : * This routine sets the value of one array element (specified by * a subscript array) to a new value specified by "dataValue". * * This handles both ordinary varlena arrays and fixed-length arrays. * * Inputs: * arraydatum: the initial array object (mustn't be NULL) * nSubscripts: number of subscripts supplied * indx[]: the subscript values * dataValue: the da

Source from the content-addressed store, hash-verified

2212 * rather than returning a NULL as the fetch operations do.
2213 */
2214Datum
2215array_set_element(Datum arraydatum,
2216 int nSubscripts,
2217 int *indx,
2218 Datum dataValue,
2219 bool isNull,
2220 int arraytyplen,
2221 int elmlen,
2222 bool elmbyval,
2223 char elmalign)
2224{
2225 ArrayType *array;
2226 ArrayType *newarray;
2227 int i,
2228 ndim,
2229 dim[MAXDIM],
2230 lb[MAXDIM],
2231 offset;
2232 char *elt_ptr;
2233 bool newhasnulls;
2234 bits8 *oldnullbitmap;
2235 int oldnitems,
2236 newnitems,
2237 olddatasize,
2238 newsize,
2239 olditemlen,
2240 newitemlen,
2241 overheadlen,
2242 oldoverheadlen,
2243 addedbefore,
2244 addedafter,
2245 lenbefore,
2246 lenafter;
2247
2248 if (arraytyplen > 0)
2249 {
2250 /*
2251 * fixed-length arrays -- these are assumed to be 1-d, 0-based. We
2252 * cannot extend them, either.
2253 */
2254 char *resultarray;
2255
2256 if (nSubscripts != 1)
2257 ereport(ERROR,
2258 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2259 errmsg("wrong number of array subscripts")));
2260
2261 if (indx[0] < 0 || indx[0] >= arraytyplen / elmlen)
2262 ereport(ERROR,
2263 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2264 errmsg("array subscript out of range")));
2265
2266 if (isNull)
2267 ereport(ERROR,
2268 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2269 errmsg("cannot assign null value to an element of a fixed-length array")));
2270
2271 resultarray = (char *) palloc(arraytyplen);

Callers 4

array_setFunction · 0.85
array_appendFunction · 0.85
array_prependFunction · 0.85
array_subscript_assignFunction · 0.85

Calls 15

ArrayCastAndSetFunction · 0.85
construct_md_arrayFunction · 0.85
pg_sub_s32_overflowFunction · 0.85
pg_add_s32_overflowFunction · 0.85
ArrayGetNItemsFunction · 0.85
ArrayCheckBoundsFunction · 0.85
ArrayGetOffsetFunction · 0.85
array_seekFunction · 0.85
array_get_isnullFunction · 0.85
array_set_isnullFunction · 0.85
array_bitmap_copyFunction · 0.85

Tested by

no test coverage detected