mysqludf/lib_mysqludf_preg

SQL String function LOWER() does not perform on result of PREG_REPLACE()

Opened this issue · 4 comments

SQL Functions LOWER() and UPPER() have no effect on the result returned by PREG_REPLACE().

See the result of this:

SELECT
lower(preg_replace('/(Editura) ?/','','Editura Corint')) as _start_nume,
lower('Editura Corint') as _nume

ytez commented

I tried this:

SELECT
lower(cast(preg_replace('/(Editura) ?/','','Editura Corint') as char(255))) as _start_nume,
lower('Editura Corint') as _nume;

I can confirm @ytez solution seems to be working on MySQL 5.1.73

ytez commented

@proditis Thanks for your checking !

In addition, I tested the field type of '_start_nume' by following:

CREATE TEMPORARY TABLE `temp`
SELECT PREG_REPLACE('/(Editura) ?/', '', 'Editura Corint') AS _start_nume, LOWER('Editura Corint') AS _nume;
SHOW FULL COLUMNS FROM `temp`;

+-------------+---------------+-----------+------+-----+---------+-------+---------------------------------+---------+
| Field       | Type          | Collation | Null | Key | Default | Extra | Privileges                      | Comment |
+-------------+---------------+-----------+------+-----+---------+-------+---------------------------------+---------+
| _start_nume | varbinary(42) | NULL      | NO   |     |         |       | select,insert,update,references |         |
| _nume       | varchar(14)   | utf8_bin  | YES  |     | NULL    |       | select,insert,update,references |         |
+-------------+---------------+-----------+------+-----+---------+-------+---------------------------------+---------+

It looks like PREG_REPLACE returns VARBINARY data on my environment (MySQL 5.6.23).
According to MySQL reference, It should be converted to a NONBINARY string,

LOWER() (and UPPER()) are ineffective when applied to binary strings (BINARY, VARBINARY, BLOB).
To perform lettercase conversion, convert the string to a nonbinary string:

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_lower

Then, the real question is: is it correct that PREG_REPLACE returns VARBINARY?