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

Commit eb62e38

Browse files
author
Nikita Glukhov
committed
Add JSON_VALUE, JSON_EXISTS, JSON_QUERY
1 parent 586a14d commit eb62e38

28 files changed

+3299
-87
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,6 +2919,18 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
29192919
APP_JUMB(opts->value_type);
29202920
}
29212921
break;
2922+
case T_JsonExpr:
2923+
{
2924+
JsonExpr *jexpr = (JsonExpr *) node;
2925+
2926+
APP_JUMB(jexpr->op);
2927+
JumbleExpr(jstate, jexpr->raw_expr);
2928+
JumbleExpr(jstate, (Node *) jexpr->path_spec);
2929+
JumbleExpr(jstate, (Node *) jexpr->passing.values);
2930+
JumbleExpr(jstate, jexpr->on_empty.default_expr);
2931+
JumbleExpr(jstate, jexpr->on_error.default_expr);
2932+
}
2933+
break;
29222934
case T_List:
29232935
foreach(temp, (List *) node)
29242936
{

src/backend/executor/execExpr.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "pgstat.h"
4545
#include "utils/builtins.h"
4646
#include "utils/datum.h"
47+
#include "utils/jsonpath.h"
4748
#include "utils/lsyscache.h"
4849
#include "utils/typcache.h"
4950

@@ -2111,6 +2112,92 @@ ExecInitExprRec(Expr *node, ExprState *state,
21112112
resnull);
21122113
break;
21132114

2115+
case T_JsonExpr:
2116+
{
2117+
JsonExpr *jexpr = castNode(JsonExpr, node);
2118+
ListCell *argexprlc;
2119+
ListCell *argnamelc;
2120+
2121+
scratch.opcode = EEOP_JSONEXPR;
2122+
scratch.d.jsonexpr.jsexpr = jexpr;
2123+
2124+
scratch.d.jsonexpr.raw_expr =
2125+
palloc(sizeof(*scratch.d.jsonexpr.raw_expr));
2126+
2127+
ExecInitExprRec((Expr *) jexpr->raw_expr, state,
2128+
&scratch.d.jsonexpr.raw_expr->value,
2129+
&scratch.d.jsonexpr.raw_expr->isnull);
2130+
2131+
scratch.d.jsonexpr.formatted_expr =
2132+
ExecInitExpr((Expr *) jexpr->formatted_expr, state->parent);
2133+
2134+
scratch.d.jsonexpr.result_expr = jexpr->result_coercion
2135+
? ExecInitExpr((Expr *) jexpr->result_coercion->expr,
2136+
state->parent)
2137+
: NULL;
2138+
2139+
scratch.d.jsonexpr.default_on_empty =
2140+
ExecInitExpr((Expr *) jexpr->on_empty.default_expr,
2141+
state->parent);
2142+
2143+
scratch.d.jsonexpr.default_on_error =
2144+
ExecInitExpr((Expr *) jexpr->on_error.default_expr,
2145+
state->parent);
2146+
2147+
if (jexpr->omit_quotes ||
2148+
(jexpr->result_coercion && jexpr->result_coercion->via_io))
2149+
{
2150+
Oid typinput;
2151+
2152+
/* lookup the result type's input function */
2153+
getTypeInputInfo(jexpr->returning.typid, &typinput,
2154+
&scratch.d.jsonexpr.input.typioparam);
2155+
fmgr_info(typinput, &scratch.d.jsonexpr.input.func);
2156+
}
2157+
2158+
scratch.d.jsonexpr.args = NIL;
2159+
2160+
forboth(argexprlc, jexpr->passing.values,
2161+
argnamelc, jexpr->passing.names)
2162+
{
2163+
Expr *argexpr = (Expr *) lfirst(argexprlc);
2164+
Value *argname = (Value *) lfirst(argnamelc);
2165+
JsonPathVariableEvalContext *var = palloc(sizeof(*var));
2166+
2167+
var->name = pstrdup(argname->val.str);
2168+
var->typid = exprType((Node *) argexpr);
2169+
var->typmod = exprTypmod((Node *) argexpr);
2170+
var->estate = ExecInitExpr(argexpr, state->parent);
2171+
var->econtext = NULL;
2172+
var->evaluated = false;
2173+
var->value = (Datum) 0;
2174+
var->isnull = true;
2175+
2176+
scratch.d.jsonexpr.args =
2177+
lappend(scratch.d.jsonexpr.args, var);
2178+
}
2179+
2180+
if (jexpr->coercions)
2181+
{
2182+
JsonCoercion **coercion;
2183+
struct JsonCoercionState *cstate;
2184+
2185+
for (cstate = &scratch.d.jsonexpr.coercions.null,
2186+
coercion = &jexpr->coercions->null;
2187+
coercion <= &jexpr->coercions->composite;
2188+
coercion++, cstate++)
2189+
{
2190+
cstate->coercion = *coercion;
2191+
cstate->estate = *coercion ?
2192+
ExecInitExpr((Expr *)(*coercion)->expr,
2193+
state->parent) : NULL;
2194+
}
2195+
}
2196+
2197+
ExprEvalPushStep(state, &scratch);
2198+
}
2199+
break;
2200+
21142201
default:
21152202
elog(ERROR, "unrecognized node type: %d",
21162203
(int) nodeTag(node));

0 commit comments

Comments
 (0)