aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeTableFuncscan.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor/nodeTableFuncscan.c')
-rw-r--r--src/backend/executor/nodeTableFuncscan.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/backend/executor/nodeTableFuncscan.c b/src/backend/executor/nodeTableFuncscan.c
index 72ca34a2287..f483221bb8e 100644
--- a/src/backend/executor/nodeTableFuncscan.c
+++ b/src/backend/executor/nodeTableFuncscan.c
@@ -28,6 +28,7 @@
#include "miscadmin.h"
#include "nodes/execnodes.h"
#include "utils/builtins.h"
+#include "utils/jsonpath.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/xml.h"
@@ -161,8 +162,9 @@ ExecInitTableFuncScan(TableFuncScan *node, EState *estate, int eflags)
scanstate->ss.ps.qual =
ExecInitQual(node->scan.plan.qual, &scanstate->ss.ps);
- /* Only XMLTABLE is supported currently */
- scanstate->routine = &XmlTableRoutine;
+ /* Only XMLTABLE and JSON_TABLE are supported currently */
+ scanstate->routine =
+ tf->functype == TFT_XMLTABLE ? &XmlTableRoutine : &JsonbTableRoutine;
scanstate->perTableCxt =
AllocSetContextCreate(CurrentMemoryContext,
@@ -182,6 +184,10 @@ ExecInitTableFuncScan(TableFuncScan *node, EState *estate, int eflags)
ExecInitExprList(tf->colexprs, (PlanState *) scanstate);
scanstate->coldefexprs =
ExecInitExprList(tf->coldefexprs, (PlanState *) scanstate);
+ scanstate->colvalexprs =
+ ExecInitExprList(tf->colvalexprs, (PlanState *) scanstate);
+ scanstate->passingvalexprs =
+ ExecInitExprList(tf->passingvalexprs, (PlanState *) scanstate);
scanstate->notnulls = tf->notnulls;
@@ -274,11 +280,12 @@ tfuncFetchRows(TableFuncScanState *tstate, ExprContext *econtext)
/*
* Each call to fetch a new set of rows - of which there may be very many
- * if XMLTABLE is being used in a lateral join - will allocate a possibly
- * substantial amount of memory, so we cannot use the per-query context
- * here. perTableCxt now serves the same function as "argcontext" does in
- * FunctionScan - a place to store per-one-call (i.e. one result table)
- * lifetime data (as opposed to per-query or per-result-tuple).
+ * if XMLTABLE or JSON_TABLE is being used in a lateral join - will
+ * allocate a possibly substantial amount of memory, so we cannot use the
+ * per-query context here. perTableCxt now serves the same function as
+ * "argcontext" does in FunctionScan - a place to store per-one-call (i.e.
+ * one result table) lifetime data (as opposed to per-query or
+ * per-result-tuple).
*/
MemoryContextSwitchTo(tstate->perTableCxt);
@@ -369,14 +376,20 @@ tfuncInitialize(TableFuncScanState *tstate, ExprContext *econtext, Datum doc)
routine->SetNamespace(tstate, ns_name, ns_uri);
}
- /* Install the row filter expression into the table builder context */
- value = ExecEvalExpr(tstate->rowexpr, econtext, &isnull);
- if (isnull)
- ereport(ERROR,
- (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
- errmsg("row filter expression must not be null")));
+ /*
+ * Install the row filter expression, if any, into the table builder
+ * context.
+ */
+ if (routine->SetRowFilter)
+ {
+ value = ExecEvalExpr(tstate->rowexpr, econtext, &isnull);
+ if (isnull)
+ ereport(ERROR,
+ (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
+ errmsg("row filter expression must not be null")));
- routine->SetRowFilter(tstate, TextDatumGetCString(value));
+ routine->SetRowFilter(tstate, TextDatumGetCString(value));
+ }
/*
* Install the column filter expressions into the table builder context.