4848#include "utils/builtins.h"
4949#include "utils/datum.h"
5050#include "utils/fmgroids.h"
51+ #include "utils/json.h"
52+ #include "utils/jsonb.h"
5153#include "utils/lsyscache.h"
5254#include "utils/memutils.h"
5355#include "utils/syscache.h"
@@ -665,6 +667,27 @@ contain_mutable_functions_walker(Node *node, void *context)
665667 context ))
666668 return true;
667669
670+ if (IsA (node , JsonCtorExpr ))
671+ {
672+ JsonCtorExpr * ctor = (JsonCtorExpr * ) node ;
673+ ListCell * lc ;
674+ bool is_jsonb =
675+ ctor -> returning -> format -> format == JS_FORMAT_JSONB ;
676+
677+ /* Check argument_type => json[b] conversions */
678+ foreach (lc , ctor -> args )
679+ {
680+ Oid typid = exprType (lfirst (lc ));
681+
682+ if (is_jsonb ?
683+ !to_jsonb_is_immutable (typid ) :
684+ !to_json_is_immutable (typid ))
685+ return true;
686+ }
687+
688+ /* Check all subnodes */
689+ }
690+
668691 if (IsA (node , SQLValueFunction ))
669692 {
670693 /* all variants of SQLValueFunction are stable */
@@ -677,12 +700,6 @@ contain_mutable_functions_walker(Node *node, void *context)
677700 return true;
678701 }
679702
680- if (IsA (node , JsonCtorExpr ))
681- {
682- /* JsonCtorExpr is stable */
683- return true;
684- }
685-
686703 /*
687704 * It should be safe to treat MinMaxExpr as immutable, because it will
688705 * depend on a non-cross-type btree comparison function, and those should
0 commit comments