mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +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:
@ -4602,6 +4602,7 @@ ExecEvalJsonBehavior(ExprContext *econtext, JsonBehavior *behavior,
|
||||
|
||||
case JSON_BEHAVIOR_NULL:
|
||||
case JSON_BEHAVIOR_UNKNOWN:
|
||||
case JSON_BEHAVIOR_EMPTY:
|
||||
*is_null = true;
|
||||
return (Datum) 0;
|
||||
|
||||
@ -4694,8 +4695,14 @@ EvalJsonPathVar(void *cxt, char *varName, int varNameLen,
|
||||
|
||||
if (!var->evaluated)
|
||||
{
|
||||
MemoryContext oldcxt = var->mcxt ?
|
||||
MemoryContextSwitchTo(var->mcxt) : NULL;
|
||||
|
||||
var->value = ExecEvalExpr(var->estate, var->econtext, &var->isnull);
|
||||
var->evaluated = true;
|
||||
|
||||
if (oldcxt)
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
}
|
||||
|
||||
if (var->isnull)
|
||||
@ -4843,6 +4850,7 @@ ExecEvalJsonExprSubtrans(JsonFunc func, ExprEvalStep *op,
|
||||
PG_CATCH();
|
||||
{
|
||||
ErrorData *edata;
|
||||
int ecategory;
|
||||
|
||||
/* Save error info in oldcontext */
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
@ -4854,8 +4862,10 @@ ExecEvalJsonExprSubtrans(JsonFunc func, ExprEvalStep *op,
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
if (ERRCODE_TO_CATEGORY(edata->sqlerrcode) !=
|
||||
ERRCODE_DATA_EXCEPTION)
|
||||
ecategory = ERRCODE_TO_CATEGORY(edata->sqlerrcode);
|
||||
|
||||
if (ecategory != ERRCODE_DATA_EXCEPTION && /* jsonpath and other data errors */
|
||||
ecategory != ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION) /* domain errors */
|
||||
ReThrowError(edata);
|
||||
|
||||
res = (Datum) 0;
|
||||
@ -4981,6 +4991,10 @@ ExecEvalJsonExpr(ExprEvalStep *op, ExprContext *econtext,
|
||||
break;
|
||||
}
|
||||
|
||||
case JSON_TABLE_OP:
|
||||
*resnull = false;
|
||||
return item;
|
||||
|
||||
default:
|
||||
elog(ERROR, "unrecognized SQL/JSON expression op %d", jexpr->op);
|
||||
return (Datum) 0;
|
||||
|
Reference in New Issue
Block a user