mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
SQL/JSON: add standard JSON constructor functions
This commit introduces the SQL/JSON standard-conforming constructors for JSON types: JSON_ARRAY() JSON_ARRAYAGG() JSON_OBJECT() JSON_OBJECTAGG() Most of the functionality was already present in PostgreSQL-specific functions, but these include some new functionality such as the ability to skip or include NULL values, and to allow duplicate keys or throw error when they are found, as well as the standard specified syntax to specify output type and format. Author: Nikita Glukhov <n.gluhov@postgrespro.ru> Author: Teodor Sigaev <teodor@sigaev.ru> Author: Oleg Bartunov <obartunov@gmail.com> Author: Alexander Korotkov <aekorotkov@gmail.com> Author: Amit Langote <amitlangote09@gmail.com> Reviewers have included (in no particular order) Andres Freund, Alexander Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zihong Yu, Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby. Discussion: https://postgr.es/m/CAF4Au4w2x-5LTnN_bxky-mq4=WOqsGsxSpENCzHRAzSnEd8+WQ@mail.gmail.com Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru Discussion: https://postgr.es/m/20220616233130.rparivafipt6doj3@alap3.anarazel.de Discussion: https://postgr.es/m/abd9b83b-aa66-f230-3d6d-734817f0995d%40postgresql.org
This commit is contained in:
@ -51,6 +51,8 @@
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/datum.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/json.h"
|
||||
#include "utils/jsonb.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/syscache.h"
|
||||
@ -383,6 +385,33 @@ contain_mutable_functions_walker(Node *node, void *context)
|
||||
context))
|
||||
return true;
|
||||
|
||||
if (IsA(node, JsonConstructorExpr))
|
||||
{
|
||||
const JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
|
||||
ListCell *lc;
|
||||
bool is_jsonb;
|
||||
|
||||
is_jsonb = ctor->returning->format->format_type == JS_FORMAT_JSONB;
|
||||
|
||||
/*
|
||||
* Check argument_type => json[b] conversions specifically. We still
|
||||
* recurse to check 'args' below, but here we want to specifically
|
||||
* check whether or not the emitted clause would fail to be immutable
|
||||
* because of TimeZone, for example.
|
||||
*/
|
||||
foreach(lc, ctor->args)
|
||||
{
|
||||
Oid typid = exprType(lfirst(lc));
|
||||
|
||||
if (is_jsonb ?
|
||||
!to_jsonb_is_immutable(typid) :
|
||||
!to_json_is_immutable(typid))
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Check all subnodes */
|
||||
}
|
||||
|
||||
if (IsA(node, NextValueExpr))
|
||||
{
|
||||
/* NextValueExpr is volatile */
|
||||
@ -2786,6 +2815,32 @@ eval_const_expressions_mutator(Node *node,
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case T_JsonValueExpr:
|
||||
{
|
||||
JsonValueExpr *jve = (JsonValueExpr *) node;
|
||||
Node *raw;
|
||||
|
||||
raw = eval_const_expressions_mutator((Node *) jve->raw_expr,
|
||||
context);
|
||||
if (raw && IsA(raw, Const))
|
||||
{
|
||||
Node *formatted;
|
||||
Node *save_case_val = context->case_val;
|
||||
|
||||
context->case_val = raw;
|
||||
|
||||
formatted = eval_const_expressions_mutator((Node *) jve->formatted_expr,
|
||||
context);
|
||||
|
||||
context->case_val = save_case_val;
|
||||
|
||||
if (formatted && IsA(formatted, Const))
|
||||
return formatted;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case T_SubPlan:
|
||||
case T_AlternativeSubPlan:
|
||||
|
||||
|
Reference in New Issue
Block a user