1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-20 05:13:53 +03:00

array_map failed to insert correct result type in an empty array.

Per example from Florian Pflug.
This commit is contained in:
Tom Lane 2004-12-17 20:58:36 +00:00
parent 1d3ee97a3c
commit 9ab182c2f1

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.100.2.1 2004/06/08 20:28:29 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.100.2.2 2004/12/17 20:58:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -2063,7 +2063,13 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType)
/* Check for empty array */
if (nitems <= 0)
PG_RETURN_ARRAYTYPE_P(v);
{
/* Return empty array */
result = (ArrayType *) palloc0(sizeof(ArrayType));
result->size = sizeof(ArrayType);
result->elemtype = retType;
PG_RETURN_ARRAYTYPE_P(result);
}
/*
* We arrange to look up info about input and return element types
@ -2247,14 +2253,9 @@ construct_md_array(Datum *elems,
if (ndims == 0)
{
/* Allocate and initialize 0-D result array */
nbytes = ARR_OVERHEAD(ndims);
result = (ArrayType *) palloc(nbytes);
result->size = nbytes;
result->ndim = ndims;
result->flags = 0;
result = (ArrayType *) palloc0(sizeof(ArrayType));
result->size = sizeof(ArrayType);
result->elemtype = elmtype;
return result;
}