8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.152 2009/01/01 17:23:49 momjian Exp $
11
+ * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.153 2009/01/30 21:21:18 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -4665,7 +4665,7 @@ array_unnest(PG_FUNCTION_ARGS)
4665
4665
/* stuff done only on the first call of the function */
4666
4666
if (SRF_IS_FIRSTCALL ())
4667
4667
{
4668
- ArrayType * arr = PG_GETARG_ARRAYTYPE_P ( 0 ) ;
4668
+ ArrayType * arr ;
4669
4669
4670
4670
/* create a function context for cross-call persistence */
4671
4671
funcctx = SRF_FIRSTCALL_INIT ();
@@ -4675,13 +4675,19 @@ array_unnest(PG_FUNCTION_ARGS)
4675
4675
*/
4676
4676
oldcontext = MemoryContextSwitchTo (funcctx -> multi_call_memory_ctx );
4677
4677
4678
+ /*
4679
+ * Get the array value and detoast if needed. We can't do this
4680
+ * earlier because if we have to detoast, we want the detoasted
4681
+ * copy to be in multi_call_memory_ctx, so it will go away when
4682
+ * we're done and not before. (If no detoast happens, we assume
4683
+ * the originally passed array will stick around till then.)
4684
+ */
4685
+ arr = PG_GETARG_ARRAYTYPE_P (0 );
4686
+
4678
4687
/* allocate memory for user context */
4679
4688
fctx = (array_unnest_fctx * ) palloc (sizeof (array_unnest_fctx ));
4680
4689
4681
- /*
4682
- * Initialize state. Note we assume that the originally passed
4683
- * array will stick around for the whole call series.
4684
- */
4690
+ /* initialize state */
4685
4691
fctx -> arr = arr ;
4686
4692
fctx -> nextelem = 0 ;
4687
4693
fctx -> numelems = ArrayGetNItems (ARR_NDIM (arr ), ARR_DIMS (arr ));
0 commit comments