diff options
| author | Alvaro Herrera | 2023-03-29 10:11:36 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2023-03-29 10:11:36 +0000 |
| commit | 7081ac46ace8c459966174400b53418683c9fe5c (patch) | |
| tree | 52590ea33eb07a2d7acf4a1461101932c3c88757 /src/backend/optimizer/util | |
| parent | 38b7437b9088b4859e4489a1a1a9ab7066f5b320 (diff) | |
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 <[email protected]>
Author: Teodor Sigaev <[email protected]>
Author: Oleg Bartunov <[email protected]>
Author: Alexander Korotkov <[email protected]>
Author: Amit Langote <[email protected]>
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/[email protected]
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/abd9b83b-aa66-f230-3d6d-734817f0995d%40postgresql.org
Diffstat (limited to 'src/backend/optimizer/util')
| -rw-r--r-- | src/backend/optimizer/util/clauses.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index fc245c60e41..a9c7bc342ec 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -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: |
