mirror of
https://github.com/postgres/postgres.git
synced 2025-07-21 16:02:15 +03:00
JSON_TABLE
This feature allows jsonb data to be treated as a table and thus used in a FROM clause like other tabular data. Data can be selected from the jsonb using jsonpath expressions, and hoisted out of nested structures in the jsonb to form multiple rows, more or less like an outer join. Nikita Glukhov Reviewers have included (in no particular order) Andres Freund, Alexander Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zhihong Yu (whose name I previously misspelled), Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby. Discussion: https://postgr.es/m/7e2cb85d-24cf-4abb-30a5-1a33715959bd@postgrespro.ru
This commit is contained in:
@ -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,
|
||||
@ -381,14 +383,17 @@ 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")));
|
||||
if (routine->SetRowFilter)
|
||||
{
|
||||
/* 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")));
|
||||
|
||||
routine->SetRowFilter(tstate, TextDatumGetCString(value));
|
||||
routine->SetRowFilter(tstate, TextDatumGetCString(value));
|
||||
}
|
||||
|
||||
/*
|
||||
* Install the column filter expressions into the table builder context.
|
||||
|
Reference in New Issue
Block a user