88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.6 1997/08/12 22:52:35 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.7 1997/08/29 09:02:50 vadim Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -365,9 +365,19 @@ postquel_execute(execution_state *es,
365365Datum
366366postquel_function (Func * funcNode ,char * * args ,bool * isNull ,bool * isDone )
367367{
368- execution_state * es ;
369- Datum result = 0 ;
370- FunctionCachePtr fcache = funcNode -> func_fcache ;
368+ execution_state * es ;
369+ Datum result = 0 ;
370+ FunctionCachePtr fcache = funcNode -> func_fcache ;
371+ CommandId savedId ;
372+
373+ /*
374+ * Before we start do anything we must save CurrentScanCommandId
375+ * to restore it before return to upper Executor. Also, we have to
376+ * set CurrentScanCommandId equal to CurrentCommandId.
377+ *- vadim 08/29/97
378+ */
379+ savedId = GetScanCommandId ();
380+ SetScanCommandId (GetCurrentCommandId ());
371381
372382es = (execution_state * )fcache -> func_state ;
373383if (es == NULL )
@@ -401,22 +411,23 @@ postquel_function(Func *funcNode, char **args, bool *isNull, bool *isDone)
401411 * If we've gone through every command in this function, we are done.
402412 */
403413if (es == (execution_state * )NULL )
414+ {
415+ /*
416+ * Reset the execution states to start over again
417+ */
418+ es = (execution_state * )fcache -> func_state ;
419+ while (es )
404420{
405- /*
406- * Reset the execution states to start over again
407- */
408- es = (execution_state * )fcache -> func_state ;
409- while (es )
410- {
411- es -> status = F_EXEC_START ;
412- es = es -> next ;
413- }
414- /*
415- * Let caller know we're finished.
416- */
417- * isDone = true;
418- return (fcache -> oneResult ) ?result : (Datum )NULL ;
421+ es -> status = F_EXEC_START ;
422+ es = es -> next ;
419423}
424+ /*
425+ * Let caller know we're finished.
426+ */
427+ * isDone = true;
428+ SetScanCommandId (savedId );
429+ return (fcache -> oneResult ) ?result : (Datum )NULL ;
430+ }
420431/*
421432 * If we got a result from a command within the function it has
422433 * to be the final command. All others shouldn't be returing
@@ -425,5 +436,6 @@ postquel_function(Func *funcNode, char **args, bool *isNull, bool *isDone)
425436Assert (LAST_POSTQUEL_COMMAND (es ) );
426437* isDone = false;
427438
439+ SetScanCommandId (savedId );
428440return result ;
429441}