Fix ruleutils_15.c's dumping of whole-row Vars in more contexts

Relevant PG commit:
43c2175121c829c8591fc5117b725f1f22bfb670
pg_15_iso_fix
naisila 2022-07-25 15:22:28 +03:00
parent c3966240fb
commit a82e54c757
1 changed files with 34 additions and 22 deletions

View File

@ -404,6 +404,8 @@ static void get_rule_expr(Node *node, deparse_context *context,
bool showimplicit); bool showimplicit);
static void get_rule_expr_toplevel(Node *node, deparse_context *context, static void get_rule_expr_toplevel(Node *node, deparse_context *context,
bool showimplicit); bool showimplicit);
static void get_rule_list_toplevel(List *lst, deparse_context *context,
bool showimplicit);
static void get_rule_expr_funccall(Node *node, deparse_context *context, static void get_rule_expr_funccall(Node *node, deparse_context *context,
bool showimplicit); bool showimplicit);
static bool looks_like_function(Node *node); static bool looks_like_function(Node *node);
@ -3283,7 +3285,7 @@ get_insert_query_def(Query *query, deparse_context *context)
/* Add the single-VALUES expression list */ /* Add the single-VALUES expression list */
appendContextKeyword(context, "VALUES (", appendContextKeyword(context, "VALUES (",
-PRETTYINDENT_STD, PRETTYINDENT_STD, 2); -PRETTYINDENT_STD, PRETTYINDENT_STD, 2);
get_rule_expr((Node *) strippedexprs, context, false); get_rule_list_toplevel(strippedexprs, context, false);
appendStringInfoChar(buf, ')'); appendStringInfoChar(buf, ')');
} }
else else
@ -5780,23 +5782,15 @@ get_rule_expr(Node *node, deparse_context *context,
case T_RowCompareExpr: case T_RowCompareExpr:
{ {
RowCompareExpr *rcexpr = (RowCompareExpr *) node; RowCompareExpr *rcexpr = (RowCompareExpr *) node;
ListCell *arg;
char *sep;
/* /*
* SQL99 allows "ROW" to be omitted when there is more than * SQL99 allows "ROW" to be omitted when there is more than
* one column, but for simplicity we always print it. * one column, but for simplicity we always print it. Within
* a ROW expression, whole-row Vars need special treatment, so
* use get_rule_list_toplevel.
*/ */
appendStringInfoString(buf, "(ROW("); appendStringInfoString(buf, "(ROW(");
sep = ""; get_rule_list_toplevel(rcexpr->largs, context, true);
foreach(arg, rcexpr->largs)
{
Node *e = (Node *) lfirst(arg);
appendStringInfoString(buf, sep);
get_rule_expr(e, context, true);
sep = ", ";
}
/* /*
* We assume that the name of the first-column operator will * We assume that the name of the first-column operator will
@ -5809,15 +5803,7 @@ get_rule_expr(Node *node, deparse_context *context,
generate_operator_name(linitial_oid(rcexpr->opnos), generate_operator_name(linitial_oid(rcexpr->opnos),
exprType(linitial(rcexpr->largs)), exprType(linitial(rcexpr->largs)),
exprType(linitial(rcexpr->rargs)))); exprType(linitial(rcexpr->rargs))));
sep = ""; get_rule_list_toplevel(rcexpr->rargs, context, true);
foreach(arg, rcexpr->rargs)
{
Node *e = (Node *) lfirst(arg);
appendStringInfoString(buf, sep);
get_rule_expr(e, context, true);
sep = ", ";
}
appendStringInfoString(buf, "))"); appendStringInfoString(buf, "))");
} }
break; break;
@ -6366,6 +6352,32 @@ get_rule_expr_toplevel(Node *node, deparse_context *context,
get_rule_expr(node, context, showimplicit); get_rule_expr(node, context, showimplicit);
} }
/*
* get_rule_list_toplevel - Parse back a list of toplevel expressions
*
* Apply get_rule_expr_toplevel() to each element of a List.
*
* This adds commas between the expressions, but caller is responsible
* for printing surrounding decoration.
*/
static void
get_rule_list_toplevel(List *lst, deparse_context *context,
bool showimplicit)
{
const char *sep;
ListCell *lc;
sep = "";
foreach(lc, lst)
{
Node *e = (Node *) lfirst(lc);
appendStringInfoString(context->buf, sep);
get_rule_expr_toplevel(e, context, showimplicit);
sep = ", ";
}
}
/* /*
* get_rule_expr_funccall - Parse back a function-call expression * get_rule_expr_funccall - Parse back a function-call expression
* *