]> granicus.if.org Git - postgresql/commitdiff
array_map failed to insert correct result type in an empty array.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Dec 2004 20:58:47 +0000 (20:58 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Dec 2004 20:58:47 +0000 (20:58 +0000)
Per example from Florian Pflug.

src/backend/utils/adt/arrayfuncs.c

index f864338897037c3a63e6bcebb4cf496b5ac79da8..bbed7603760046a9eece6830e90b14034033b70b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.81 2002/09/18 21:35:22 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.81.2.1 2004/12/17 20:58:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1488,7 +1488,14 @@ 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 *) palloc(sizeof(ArrayType));
+               MemSet(result, 0, sizeof(ArrayType));
+               result->size = sizeof(ArrayType);
+               result->elemtype = retType;
+               PG_RETURN_ARRAYTYPE_P(result);
+       }
 
        /* Lookup source and result types. Unneeded variables are reused. */
        system_cache_lookup(inpType, false, &inp_typlen, &inp_typbyval,