diff --git a/contrib/babelfishpg_tsql/src/string.c b/contrib/babelfishpg_tsql/src/string.c index ae0884923c8..154a1ed5559 100644 --- a/contrib/babelfishpg_tsql/src/string.c +++ b/contrib/babelfishpg_tsql/src/string.c @@ -801,7 +801,7 @@ float_str(PG_FUNCTION_ARGS) } } - return return_varchar_pointer(buf, size); + return return_varchar_pointer(buf, strlen(buf)); } /* diff --git a/test/JDBC/expected/str.out b/test/JDBC/expected/str.out index b1f2a213f39..b299fc080e4 100644 --- a/test/JDBC/expected/str.out +++ b/test/JDBC/expected/str.out @@ -523,6 +523,32 @@ GO -- ============================================= -- CLEANUP -- ============================================= +-- ============================================= +-- STRING CONCATENATION WITH STR() (GitHub Issue #4297) +-- ============================================= +-- STR() result should not truncate strings appended after it +SELECT 'distance:' + STR(123, 4, 0) + ' mi'; +GO +~~START~~ +varchar +distance: 123 mi +~~END~~ + +SELECT 'val=' + STR(42, 2, 0) + ',done'; +GO +~~START~~ +varchar +val=42,done +~~END~~ + +SELECT STR(1, 1, 0) + ' suffix'; +GO +~~START~~ +varchar +1 suffix +~~END~~ + + -- Drop Views DROP VIEW str_v1; DROP VIEW str_v2; diff --git a/test/JDBC/input/functions/string_functions/str.sql b/test/JDBC/input/functions/string_functions/str.sql index a0b3c00f43a..4ed31c0b8f2 100644 --- a/test/JDBC/input/functions/string_functions/str.sql +++ b/test/JDBC/input/functions/string_functions/str.sql @@ -385,6 +385,19 @@ GO -- CLEANUP -- ============================================= +-- ============================================= +-- STRING CONCATENATION WITH STR() (GitHub Issue #4297) +-- ============================================= +-- STR() result should not truncate strings appended after it +SELECT 'distance:' + STR(123, 4, 0) + ' mi'; +GO + +SELECT 'val=' + STR(42, 2, 0) + ',done'; +GO + +SELECT STR(1, 1, 0) + ' suffix'; +GO + -- Drop Views DROP VIEW str_v1; DROP VIEW str_v2;