From aae6e31bd33cc13cfc8b5965561b82e1e6a9c4ca Mon Sep 17 00:00:00 2001 From: Shameem Ahmed Date: Mon, 13 Jan 2025 06:19:45 +0000 Subject: [PATCH] Update logic for explicit collate or extra parenthesis Signed-off-by: Shameem Ahmed --- contrib/babelfishpg_tsql/src/pltsql_ruleutils.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/pltsql_ruleutils.c b/contrib/babelfishpg_tsql/src/pltsql_ruleutils.c index c0f0f02cb2..65795b870b 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_ruleutils.c +++ b/contrib/babelfishpg_tsql/src/pltsql_ruleutils.c @@ -1434,14 +1434,16 @@ get_rule_expr(Node *node, deparse_context *context, CollateExpr *collate = (CollateExpr *) node; Node *arg = (Node *) collate->arg; - const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); + // const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); - if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) + // if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) + if (!PRETTY_PAREN(context)) appendStringInfoChar(buf, '('); get_rule_expr_paren(arg, context, showimplicit, node); appendStringInfo(buf, " COLLATE %s", generate_tsql_collation_name(collate->collOid)); - if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) + // if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) + if (!PRETTY_PAREN(context)) appendStringInfoChar(buf, ')'); } break; @@ -2648,10 +2650,11 @@ get_coercion_expr(Node *arg, deparse_context *context, } else { - if (!PRETTY_PAREN(context)) + const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false); + if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) appendStringInfoChar(buf, '('); get_rule_expr_paren(arg, context, false, parentNode); - if (!PRETTY_PAREN(context)) + if (!PRETTY_PAREN(context) && (!dump_restore || (dump_restore && strcmp(dump_restore, "on") != 0))) appendStringInfoChar(buf, ')'); }