diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-10-25 14:25:10 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-10-25 14:25:10 -0400 |
commit | c6873eac4c33720140240cdbd1a663fecc922c57 (patch) | |
tree | 7ad25e662c9c453e455bb31bab2b1937a90321ee /src/backend/utils/adt/ruleutils.c | |
parent | ef55e294e66725c412d55b9689328235141d816d (diff) | |
download | postgresql-c6873eac4c33720140240cdbd1a663fecc922c57.tar.gz postgresql-c6873eac4c33720140240cdbd1a663fecc922c57.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index d4279c0f4e5..a5cc48b47cc 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -4368,6 +4368,7 @@ print_parameter_expr(Node *expr, ListCell *ancestor_cell, { deparse_namespace save_dpns; bool save_varprefix; + bool need_paren; /* Switch attention to the ancestor plan node */ push_ancestor_plan(dpns, ancestor_cell, &save_dpns); @@ -4380,13 +4381,21 @@ print_parameter_expr(Node *expr, ListCell *ancestor_cell, context->varprefix = true; /* - * We don't need to add parentheses because a Param's expansion is - * (currently) always a Var or Aggref. + * A Param's expansion is typically a Var, Aggref, or upper-level Param, + * which wouldn't need extra parentheses. Otherwise, insert parens to + * ensure the expression looks atomic. */ - Assert(IsA(expr, Var) || IsA(expr, Aggref)); + need_paren = !(IsA(expr, Var) || + IsA(expr, Aggref) || + IsA(expr, Param)); + if (need_paren) + appendStringInfoChar(context->buf, '('); get_rule_expr(expr, context, false); + if (need_paren) + appendStringInfoChar(context->buf, ')'); + context->varprefix = save_varprefix; pop_ancestor_plan(dpns, &save_dpns); |