diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index bf66df3c7a..bddbf95993 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -8331,14 +8331,11 @@ rewrite_string_agg_query(TSqlParser::STRING_AGGContext *ctx) { if (ctx->WITHIN() && ctx->order_by_clause()) { - rewritten_query_fragment.emplace(std::make_pair(ctx->RR_BRACKET()[0]->getSymbol()->getStartIndex(), std::make_pair(::getFullText(ctx->RR_BRACKET()[0]), std::string(" ") + ::getFullText(ctx->order_by_clause()) + ::getFullText(ctx->RR_BRACKET()[0])))); - - /* remove block (WITHIN GROUP LR_BRACKET order_by_clause RR_BRACKET) */ + /* remove block (RR_BRACKET WITHIN GROUP LR_BRACKET) */ + rewritten_query_fragment.emplace(std::make_pair(ctx->RR_BRACKET()[0]->getSymbol()->getStartIndex(), std::make_pair(::getFullText(ctx->RR_BRACKET()[0]), ""))); rewritten_query_fragment.emplace(std::make_pair(ctx->WITHIN()->getSymbol()->getStartIndex(), std::make_pair(::getFullText(ctx->WITHIN()), ""))); rewritten_query_fragment.emplace(std::make_pair(ctx->GROUP()->getSymbol()->getStartIndex(), std::make_pair(::getFullText(ctx->GROUP()), ""))); rewritten_query_fragment.emplace(std::make_pair(ctx->LR_BRACKET()[1]->getSymbol()->getStartIndex(), std::make_pair(::getFullText(ctx->LR_BRACKET()[1]), ""))); - rewritten_query_fragment.emplace(std::make_pair(ctx->order_by_clause()->start->getStartIndex(), std::make_pair(::getFullText(ctx->order_by_clause()), ""))); - rewritten_query_fragment.emplace(std::make_pair(ctx->RR_BRACKET()[1]->getSymbol()->getStartIndex(), std::make_pair(::getFullText(ctx->RR_BRACKET()[1]), ""))); } if (ctx->STRING_AGG()) diff --git a/test/JDBC/expected/string_agg_within-vu-verify.out b/test/JDBC/expected/string_agg_within-vu-verify.out index be164014f4..9ebea5f9f9 100644 --- a/test/JDBC/expected/string_agg_within-vu-verify.out +++ b/test/JDBC/expected/string_agg_within-vu-verify.out @@ -305,6 +305,42 @@ s-gu-ev-by ~~END~~ +SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY trim(a) ASC) FROM string_agg_t GROUP BY g ORDER BY g +GO +~~START~~ +varchar +az-cx-dw-ht +s-by-ev-gu +~~END~~ + + +SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY trim(a) DESC) FROM string_agg_t GROUP BY g ORDER BY g +GO +~~START~~ +varchar +ht-dw-cx-az +gu-ev-by-s +~~END~~ + + +SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY translate(a, 'a', 'b') ASC) FROM string_agg_t GROUP BY g ORDER BY g +GO +~~START~~ +varchar +az-cx-dw-ht +s-by-ev-gu +~~END~~ + + +SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY translate(a, 'a', 'b') DESC) FROM string_agg_t GROUP BY g ORDER BY g +GO +~~START~~ +varchar +ht-dw-cx-az +gu-ev-by-s +~~END~~ + + SELECT STRING_AGG(a, char(10)) WITHIN GROUP (ORDER BY a ASC) FROM string_agg_t GROUP BY g ORDER BY g GO ~~START~~ diff --git a/test/JDBC/input/functions/string_functions/string_agg_within-vu-verify.sql b/test/JDBC/input/functions/string_functions/string_agg_within-vu-verify.sql index 43da3af3ef..8ee1576533 100644 --- a/test/JDBC/input/functions/string_functions/string_agg_within-vu-verify.sql +++ b/test/JDBC/input/functions/string_functions/string_agg_within-vu-verify.sql @@ -105,6 +105,18 @@ GO SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY concat(a,b) DESC) FROM string_agg_t GROUP BY g ORDER BY g GO +SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY trim(a) ASC) FROM string_agg_t GROUP BY g ORDER BY g +GO + +SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY trim(a) DESC) FROM string_agg_t GROUP BY g ORDER BY g +GO + +SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY translate(a, 'a', 'b') ASC) FROM string_agg_t GROUP BY g ORDER BY g +GO + +SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY translate(a, 'a', 'b') DESC) FROM string_agg_t GROUP BY g ORDER BY g +GO + SELECT STRING_AGG(a, char(10)) WITHIN GROUP (ORDER BY a ASC) FROM string_agg_t GROUP BY g ORDER BY g GO