From baf42e7b4a83ce88e89ed7d551f2286e2016de1b Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Thu, 10 May 2018 18:32:22 +0100 Subject: [PATCH] MCOL-1390 Fix SUBSTRING_INDEX for negative count If negative count number is more than the number of characters in the string then it should always return the string. For example if a table contains SUBSTRING_INDEX('zzz', 'z', -5) should return 'zzz'. Before this patch it would return NULL. --- utils/funcexp/func_substring_index.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/funcexp/func_substring_index.cpp b/utils/funcexp/func_substring_index.cpp index e3ec80b5f..a4b9fb9a6 100644 --- a/utils/funcexp/func_substring_index.cpp +++ b/utils/funcexp/func_substring_index.cpp @@ -71,6 +71,9 @@ std::string Func_substring_index::getStrVal(rowgroup::Row& row, if ( count > (int64_t) end ) return str; + if (( count < 0 ) && ((count * -1) > end)) + return str; + string value = str; if ( count > 0 ) {