Skip to content

Commit c6873ea

Browse files
committed
Fix overly-enthusiastic Assert in printing of Param reference expressions.
A NestLoopParam's value can only be a Var or Aggref, but this isn't the case in general for SubPlan parameters, so print_parameter_expr had better be prepared to cope. Brain fade in my recent patch to print the referenced expression instead of just printing $N for PARAM_EXEC Params. Per report from Pavel Stehule.
1 parent ef55e29 commit c6873ea

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4368,6 +4368,7 @@ print_parameter_expr(Node *expr, ListCell *ancestor_cell,
43684368
{
43694369
deparse_namespace save_dpns;
43704370
bool save_varprefix;
4371+
bool need_paren;
43714372

43724373
/* Switch attention to the ancestor plan node */
43734374
push_ancestor_plan(dpns, ancestor_cell, &save_dpns);
@@ -4380,13 +4381,21 @@ print_parameter_expr(Node *expr, ListCell *ancestor_cell,
43804381
context->varprefix = true;
43814382

43824383
/*
4383-
* We don't need to add parentheses because a Param's expansion is
4384-
* (currently) always a Var or Aggref.
4384+
* A Param's expansion is typically a Var, Aggref, or upper-level Param,
4385+
* which wouldn't need extra parentheses. Otherwise, insert parens to
4386+
* ensure the expression looks atomic.
43854387
*/
4386-
Assert(IsA(expr, Var) || IsA(expr, Aggref));
4388+
need_paren = !(IsA(expr, Var) ||
4389+
IsA(expr, Aggref) ||
4390+
IsA(expr, Param));
4391+
if (need_paren)
4392+
appendStringInfoChar(context->buf, '(');
43874393

43884394
get_rule_expr(expr, context, false);
43894395

4396+
if (need_paren)
4397+
appendStringInfoChar(context->buf, ')');
4398+
43904399
context->varprefix = save_varprefix;
43914400

43924401
pop_ancestor_plan(dpns, &save_dpns);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy