Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 48a7af3

Browse files
author
Nikita Glukhov
committed
Add json support for JSON_TABLE
1 parent fdef26e commit 48a7af3

File tree

5 files changed

+1530
-13
lines changed

5 files changed

+1530
-13
lines changed

src/backend/executor/nodeTableFuncscan.c

Lines changed: 4 additions & 1 deletion
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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4463,19 +4463,12 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
44634463
Node *expr = jsexpr->formatted_expr ?
44644464
jsexpr->formatted_expr : jsexpr->raw_expr;
44654465

4466-
44674466
jsexpr->returning.format.type = JS_FORMAT_DEFAULT;
44684467
jsexpr->returning.format.encoding = JS_ENC_DEFAULT;
44694468
jsexpr->returning.format.location = -1;
44704469
jsexpr->returning.typid = exprType(expr);
44714470
jsexpr->returning.typmod = -1;
44724471

4473-
if (jsexpr->returning.typid != JSONBOID)
4474-
ereport(ERROR,
4475-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4476-
errmsg("JSON_TABLE() is not yet implemented for json type"),
4477-
parser_errposition(pstate, func->location)));
4478-
44794472
break;
44804473
}
44814474
}

src/include/utils/jsonpath.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ extern Datum JsonPathQuery(Datum json, JsonPath *jp, JsonWrapper wrapper,
309309

310310
extern Datum EvalJsonPathVar(void *cxt, bool *isnull);
311311

312+
extern const TableFuncRoutine JsonTableRoutine;
312313
extern const TableFuncRoutine JsonbTableRoutine;
313314

314315
#endif

0 commit comments

Comments
 (0)