mysqludf / lib_mysqludf_preg

Use PCRE regular expressions directly in MySQL
http://www.mysqludf.org/lib_mysqludf_preg
Other
138 stars 26 forks source link

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

Open andrixnet opened 10 years ago

andrixnet commented 10 years ago

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 9 years ago

I tried this:

SELECT
lower(cast(preg_replace('/(Editura) ?/','','Editura Corint') as char(255))) as _start_nume,
lower('Editura Corint') as _nume;
proditis commented 9 years ago

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

ytez commented 9 years ago

@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

andrixnet commented 9 years ago

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