* initArrayResultArr - initialize an empty ArrayBuildStateArr * * array_type is the array type (must be a valid varlena array type) * element_type is the type of the array's elements (lookup if InvalidOid) * rcontext is where to keep working state * subcontext is a flag determining whether to use a separate memory context */
| 5385 | * subcontext is a flag determining whether to use a separate memory context |
| 5386 | */ |
| 5387 | ArrayBuildStateArr * |
| 5388 | initArrayResultArr(Oid array_type, Oid element_type, MemoryContext rcontext, |
| 5389 | bool subcontext) |
| 5390 | { |
| 5391 | ArrayBuildStateArr *astate; |
| 5392 | MemoryContext arr_context = rcontext; /* by default use the parent ctx */ |
| 5393 | |
| 5394 | /* Lookup element type, unless element_type already provided */ |
| 5395 | if (!OidIsValid(element_type)) |
| 5396 | { |
| 5397 | element_type = get_element_type(array_type); |
| 5398 | |
| 5399 | if (!OidIsValid(element_type)) |
| 5400 | ereport(ERROR, |
| 5401 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 5402 | errmsg("data type %s is not an array type", |
| 5403 | format_type_be(array_type)))); |
| 5404 | } |
| 5405 | |
| 5406 | /* Make a temporary context to hold all the junk */ |
| 5407 | if (subcontext) |
| 5408 | arr_context = AllocSetContextCreate(rcontext, |
| 5409 | "accumArrayResultArr", |
| 5410 | ALLOCSET_DEFAULT_SIZES); |
| 5411 | |
| 5412 | /* Note we initialize all fields to zero */ |
| 5413 | astate = (ArrayBuildStateArr *) |
| 5414 | MemoryContextAllocZero(arr_context, sizeof(ArrayBuildStateArr)); |
| 5415 | astate->mcontext = arr_context; |
| 5416 | astate->private_cxt = subcontext; |
| 5417 | |
| 5418 | /* Save relevant datatype information */ |
| 5419 | astate->array_type = array_type; |
| 5420 | astate->element_type = element_type; |
| 5421 | |
| 5422 | return astate; |
| 5423 | } |
| 5424 | |
| 5425 | /* |
| 5426 | * accumArrayResultArr - accumulate one (more) sub-array for an array result |
no test coverage detected