summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2002-08-30 00:28:41 +0000
committerTom Lane2002-08-30 00:28:41 +0000
commite107f3a7e3feb7eaef8853ba117465f4f3f8ceed (patch)
treed28fb377b7d00f8171c208cc5ad9ceaec7a623ab /src/include
parent82ccb420d5c6f62cec1bf042cf0b6472fabdff42 (diff)
PL/pgSQL functions can return sets. Neil Conway's patch, modified so
that the functionality is available to anyone via ReturnSetInfo, rather than hard-wiring it to PL/pgSQL.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/executor/executor.h5
-rw-r--r--src/include/fmgr.h5
-rw-r--r--src/include/nodes/execnodes.h47
3 files changed, 29 insertions, 28 deletions
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 88104565976..31a2b4a2399 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: executor.h,v 1.74 2002/08/29 00:17:06 tgl Exp $
+ * $Id: executor.h,v 1.75 2002/08/30 00:28:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -80,6 +80,9 @@ extern Datum ExecMakeFunctionResult(FunctionCachePtr fcache,
ExprContext *econtext,
bool *isNull,
ExprDoneCond *isDone);
+extern Tuplestorestate *ExecMakeTableFunctionResult(Expr *funcexpr,
+ ExprContext *econtext,
+ TupleDesc *returnDesc);
extern Datum ExecEvalExpr(Node *expression, ExprContext *econtext,
bool *isNull, ExprDoneCond *isDone);
extern Datum ExecEvalExprSwitchContext(Node *expression, ExprContext *econtext,
diff --git a/src/include/fmgr.h b/src/include/fmgr.h
index 74e90c93001..7b04a1d7058 100644
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: fmgr.h,v 1.22 2002/06/20 20:29:42 momjian Exp $
+ * $Id: fmgr.h,v 1.23 2002/08/30 00:28:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -45,8 +45,7 @@ typedef struct FmgrInfo
* count */
bool fn_strict; /* function is "strict" (NULL in => NULL
* out) */
- bool fn_retset; /* function returns a set (over multiple
- * calls) */
+ bool fn_retset; /* function returns a set */
void *fn_extra; /* extra space for use by handler */
MemoryContext fn_mcxt; /* memory context to store fn_extra in */
} FmgrInfo;
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 6e146e2ca6d..3081a6842eb 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: execnodes.h,v 1.72 2002/08/29 00:17:06 tgl Exp $
+ * $Id: execnodes.h,v 1.73 2002/08/30 00:28:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,6 +21,8 @@
#include "fmgr.h"
#include "nodes/params.h"
#include "nodes/primnodes.h"
+#include "utils/tuplestore.h"
+
/* ----------------
* IndexInfo information
@@ -126,19 +128,31 @@ typedef enum
} ExprDoneCond;
/*
+ * Return modes for functions returning sets. Note values must be chosen
+ * as separate bits so that a bitmask can be formed to indicate supported
+ * modes.
+ */
+typedef enum
+{
+ SFRM_ValuePerCall = 0x01, /* one value returned per call */
+ SFRM_Materialize = 0x02 /* result set instantiated in Tuplestore */
+} SetFunctionReturnMode;
+
+/*
* When calling a function that might return a set (multiple rows),
* a node of this type is passed as fcinfo->resultinfo to allow
* return status to be passed back. A function returning set should
- * raise an error if no such resultinfo is provided. The ExprContext
- * in which the function is being called is also made available.
- *
- * XXX this mechanism is a quick hack and probably needs to be redesigned.
+ * raise an error if no such resultinfo is provided.
*/
typedef struct ReturnSetInfo
{
NodeTag type;
- ExprDoneCond isDone;
- ExprContext *econtext;
+ ExprContext *econtext; /* context function is being called in */
+ int allowedModes; /* bitmask: return modes caller can handle */
+ SetFunctionReturnMode returnMode; /* actual return mode */
+ ExprDoneCond isDone; /* status for ValuePerCall mode */
+ Tuplestorestate *setResult; /* return object for Materialize mode */
+ TupleDesc setDesc; /* descriptor for Materialize mode */
} ReturnSetInfo;
/* ----------------
@@ -509,32 +523,17 @@ typedef struct SubqueryScanState
* Function nodes are used to scan the results of a
* function appearing in FROM (typically a function returning set).
*
- * functionmode function operating mode
- * tupdesc function's return tuple description
+ * tupdesc expected return tuple description
* tuplestorestate private state of tuplestore.c
* funcexpr function expression being evaluated
- * returnsTuple does function return tuples?
- * fn_typeid OID of function return type
- * fn_typtype return type's typtype
* ----------------
*/
-typedef enum FunctionMode
-{
- PM_REPEATEDCALL,
- PM_MATERIALIZE,
- PM_QUERY
-} FunctionMode;
-
typedef struct FunctionScanState
{
CommonScanState csstate; /* its first field is NodeTag */
- FunctionMode functionmode;
TupleDesc tupdesc;
- void *tuplestorestate;
+ Tuplestorestate *tuplestorestate;
Node *funcexpr;
- bool returnsTuple;
- Oid fn_typeid;
- char fn_typtype;
} FunctionScanState;
/* ----------------------------------------------------------------