}
-/*
- * create_singleton_array - make a one-element array
- *
- * If desired, the caller can ask for it to be higher than one-dimensional.
- * Caller's fcinfo must be passed in, as we use fn_extra for caching.
- */
-ArrayType *
-create_singleton_array(FunctionCallInfo fcinfo,
- Oid element_type,
- Datum element,
- bool isNull,
- int ndims)
-{
- Datum dvalues[1];
- bool nulls[1];
- int16 typlen;
- bool typbyval;
- char typalign;
- int dims[MAXDIM];
- int lbs[MAXDIM];
- int i;
- ArrayMetaState *my_extra;
-
- if (ndims < 1)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("invalid number of dimensions: %d", ndims)));
- if (ndims > MAXDIM)
- ereport(ERROR,
- (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
- ndims, MAXDIM)));
-
- dvalues[0] = element;
- nulls[0] = isNull;
-
- for (i = 0; i < ndims; i++)
- {
- dims[i] = 1;
- lbs[i] = 1;
- }
-
- /*
- * We arrange to look up info about element type only once per series of
- * calls, assuming the element type doesn't change underneath us.
- */
- my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
- if (my_extra == NULL)
- {
- fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
- sizeof(ArrayMetaState));
- my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
- my_extra->element_type = ~element_type;
- }
-
- if (my_extra->element_type != element_type)
- {
- /* Get info about element type */
- get_typlenbyvalalign(element_type,
- &my_extra->typlen,
- &my_extra->typbyval,
- &my_extra->typalign);
- my_extra->element_type = element_type;
- }
- typlen = my_extra->typlen;
- typbyval = my_extra->typbyval;
- typalign = my_extra->typalign;
-
- return construct_md_array(dvalues, nulls, ndims, dims, lbs, element_type,
- typlen, typbyval, typalign);
-}
-
-
/*
* ARRAY_AGG(anynonarray) aggregate function
*/
*/
if (fldsep_len < 1)
{
+ Datum elems[1];
+ bool nulls[1];
+ int dims[1];
+ int lbs[1];
+
text_position_cleanup(&state);
/* single element can be a NULL too */
is_null = null_string ? text_isequal(inputstring, null_string) : false;
- PG_RETURN_ARRAYTYPE_P(create_singleton_array(fcinfo, TEXTOID,
- PointerGetDatum(inputstring),
- is_null, 1));
+
+ elems[0] = PointerGetDatum(inputstring);
+ nulls[0] = is_null;
+ dims[0] = 1;
+ lbs[0] = 1;
+ /* XXX: this hardcodes assumptions about the text type */
+ PG_RETURN_ARRAYTYPE_P(construct_md_array(elems, nulls,
+ 1, dims, lbs,
+ TEXTOID, -1, false, 'i'));
}
start_posn = 1;