Description:
Output:
======
mysql> select SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775806);
+-------------------------------------------------------------+
| SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775806) |
+-------------------------------------------------------------+
| www.mysql |
+-------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775807);
+-------------------------------------------------------------+
| SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775807) |
+-------------------------------------------------------------+
| www |
+-------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc |
+-----------+
1 row in set (0.00 sec)
Problem:
=======
Quote from manual
https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_substring-index
:
=====
SUBSTRING_INDEX(str,delim,count)
Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.
=====
When count is negative, the result should return right part/all of str.
However, in the provided two examples, left part of str is returned, which is incorrect.
How to repeat:
select SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775806);
select SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775807);
Suggested fix:
For the following two SQLs, the whole str ("www.mysql.com") is returned.