Skip to content

Commit f54db03

Browse files
author
Nikita Glukhov
committed
Add json support for JSON_TABLE
1 parent 0e439b1 commit f54db03

File tree

5 files changed

+1530
-13
lines changed

5 files changed

+1530
-13
lines changed

src/backend/executor/nodeTableFuncscan.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
#include "postgres.h"
2424

2525
#include "nodes/execnodes.h"
26+
#include "catalog/pg_type.h"
2627
#include "executor/executor.h"
2728
#include "executor/nodeTableFuncscan.h"
2829
#include "executor/tablefunc.h"
2930
#include "miscadmin.h"
31+
#include "nodes/nodeFuncs.h"
3032
#include "utils/builtins.h"
3133
#include "utils/jsonpath.h"
3234
#include "utils/lsyscache.h"
@@ -170,7 +172,8 @@ ExecInitTableFuncScan(TableFuncScan *node, EState *estate, int eflags)
170172

171173
/* Only XMLTABLE and JSON_TABLE are supported currently */
172174
scanstate->routine =
173-
tf->functype == TFT_XMLTABLE ? &XmlTableRoutine : &JsonbTableRoutine;
175+
tf->functype == TFT_XMLTABLE ? &XmlTableRoutine :
176+
exprType(tf->docexpr) == JSONBOID ? &JsonbTableRoutine : &JsonTableRoutine;
174177

175178
scanstate->perValueCxt =
176179
AllocSetContextCreate(CurrentMemoryContext,

src/backend/parser/parse_expr.c

-7
Original file line numberDiff line numberDiff line change
@@ -4633,19 +4633,12 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
46334633
Node *expr = jsexpr->formatted_expr ?
46344634
jsexpr->formatted_expr : jsexpr->raw_expr;
46354635

4636-
46374636
jsexpr->returning.format.type = JS_FORMAT_DEFAULT;
46384637
jsexpr->returning.format.encoding = JS_ENC_DEFAULT;
46394638
jsexpr->returning.format.location = -1;
46404639
jsexpr->returning.typid = exprType(expr);
46414640
jsexpr->returning.typmod = -1;
46424641

4643-
if (jsexpr->returning.typid != JSONBOID)
4644-
ereport(ERROR,
4645-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4646-
errmsg("JSON_TABLE() is not yet implemented for json type"),
4647-
parser_errposition(pstate, func->location)));
4648-
46494642
break;
46504643
}
46514644
}

src/include/utils/jsonpath.h

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ extern Datum JsonPathQuery(Datum json, JsonPath *jp, JsonWrapper wrapper,
329329

330330
extern Datum EvalJsonPathVar(void *cxt, bool *isnull);
331331

332+
extern const TableFuncRoutine JsonTableRoutine;
332333
extern const TableFuncRoutine JsonbTableRoutine;
333334

334335
#endif

0 commit comments

Comments
 (0)