Skip to content

Commit

Permalink
Deparser: Correctly set A_EXPR context in deparseExpr for deparseAExpr
Browse files Browse the repository at this point in the history
Note that the deparseAExpr function (used for deparsing A_Expr nodes)
can be called from both a_expr and b_expr contexts, but we previously
always passed NONE as the context.

Besides now passing down the context, the function also used to add
outer parenthesis to AEXPR_OP calls. This appears unnecessary (b_expr
allows operator expressions without wrapping parenthesis) and was not
utilized in practice, so remove that to avoid extra parenthesis.
  • Loading branch information
lfittl committed Dec 18, 2024
1 parent 6e60a4f commit f412d53
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/postgres_deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static void deparseExpr(StringInfo str, Node *node, DeparseNodeContext context)
deparseCollateClause(str, castNode(CollateClause, node));
break;
case T_A_Expr:
deparseAExpr(str, castNode(A_Expr, node), DEPARSE_NODE_CONTEXT_NONE);
deparseAExpr(str, castNode(A_Expr, node), DEPARSE_NODE_CONTEXT_A_EXPR);
break;
case T_BoolExpr:
deparseBoolExpr(str, castNode(BoolExpr, node));
Expand Down Expand Up @@ -3057,10 +3057,6 @@ static void deparseAExpr(StringInfo str, A_Expr* a_expr, DeparseNodeContext cont
switch (a_expr->kind) {
case AEXPR_OP: /* normal operator */
{
bool need_outer_parens = context == DEPARSE_NODE_CONTEXT_A_EXPR;

if (need_outer_parens)
appendStringInfoChar(str, '(');
if (a_expr->lexpr != NULL)
{
if (need_lexpr_parens)
Expand All @@ -3080,9 +3076,6 @@ static void deparseAExpr(StringInfo str, A_Expr* a_expr, DeparseNodeContext cont
if (need_rexpr_parens)
appendStringInfoChar(str, ')');
}

if (need_outer_parens)
appendStringInfoChar(str, ')');
}
return;
case AEXPR_OP_ANY: /* scalar op ANY (array) */
Expand Down

0 comments on commit f412d53

Please sign in to comment.