From f6a2529920cff76cb6e37ea840122574404dde8b Mon Sep 17 00:00:00 2001 From: Amit Langote Date: Mon, 8 Apr 2024 16:02:40 +0900 Subject: Fix JsonExpr deparsing to emit QUOTES and WRAPPER correctly Currently, get_json_expr_options() does not emit the default values for QUOTES (KEEP QUOTES) and WRAPPER (WITHOUT WRAPPER). That causes the deparsed JSON_TABLE() columns, such as those contained in a a view's query, to behave differently when executed than the original definition. That's because the rules encoded in transformJsonTableColumns() will choose either JSON_VALUE() or JSON_QUERY() as implementation to execute a given column's path expression depending on the QUOTES and WRAPPER specificationd and they have slightly different semantics. Reported-by: Jian He Discussion: https://postgr.es/m/CACJufxEqhqsfrg_p7EMyo5zak3d767iFDL8vz_4%3DZBHpOtrghw%40mail.gmail.com --- src/backend/utils/adt/ruleutils.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/backend/utils/adt/ruleutils.c') diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 411841047d3..466d9576a21 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -8848,9 +8848,15 @@ get_json_expr_options(JsonExpr *jsexpr, deparse_context *context, appendStringInfo(context->buf, " WITH CONDITIONAL WRAPPER"); else if (jsexpr->wrapper == JSW_UNCONDITIONAL) appendStringInfo(context->buf, " WITH UNCONDITIONAL WRAPPER"); + /* The default */ + else if (jsexpr->wrapper == JSW_NONE || jsexpr->wrapper == JSW_UNSPEC) + appendStringInfo(context->buf, " WITHOUT WRAPPER"); if (jsexpr->omit_quotes) appendStringInfo(context->buf, " OMIT QUOTES"); + /* The default */ + else + appendStringInfo(context->buf, " KEEP QUOTES"); } if (jsexpr->on_empty && jsexpr->on_empty->btype != default_behavior) -- cgit v1.2.3