aboutsummaryrefslogtreecommitdiff
path: root/contrib/tablefunc/tablefunc.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-11-30 23:24:08 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-11-30 23:24:08 +0000
commiteea4890c08200ef97e565ea7957ea58cab9a5f33 (patch)
treed022857ffb3e014c897aab9b1765f289a93fe2a7 /contrib/tablefunc/tablefunc.c
parent25a4f1afec301b8358cde28099b68bf43f18d5b4 (diff)
downloadpostgresql-eea4890c08200ef97e565ea7957ea58cab9a5f33.tar.gz
postgresql-eea4890c08200ef97e565ea7957ea58cab9a5f33.zip
Fix dblink and tablefunc to not return with the wrong CurrentMemoryContext.
Per buildfarm results.
Diffstat (limited to 'contrib/tablefunc/tablefunc.c')
-rw-r--r--contrib/tablefunc/tablefunc.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index 0be013b9084..26886b2af9d 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -381,11 +381,6 @@ crosstab(PG_FUNCTION_ARGS)
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
- /*
- * switch to memory context appropriate for multiple function calls
- */
- oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
-
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */
@@ -426,9 +421,6 @@ crosstab(PG_FUNCTION_ARGS)
SRF_RETURN_DONE(funcctx);
}
- /* SPI switches context on us, so reset it */
- MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
-
/* get a tuple descriptor for our result type */
switch (get_call_result_type(fcinfo, NULL, &tupdesc))
{
@@ -448,9 +440,6 @@ crosstab(PG_FUNCTION_ARGS)
break;
}
- /* make sure we have a persistent copy of the tupdesc */
- tupdesc = CreateTupleDescCopy(tupdesc);
-
/*
* Check that return tupdesc is compatible with the data we got from
* SPI, at least based on number and type of attributes
@@ -462,6 +451,14 @@ crosstab(PG_FUNCTION_ARGS)
"incompatible")));
/*
+ * switch to memory context appropriate for multiple function calls
+ */
+ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
+
+ /* make sure we have a persistent copy of the tupdesc */
+ tupdesc = CreateTupleDescCopy(tupdesc);
+
+ /*
* Generate attribute metadata needed later to produce tuples from raw
* C strings
*/