Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andrixnet opened this issue Nov 18, 2014 · 4 comments

Comments

@andrixnet
Copy link

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
Copy link

ytez commented May 20, 2015

I tried this:

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

@proditis
Copy link

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

@ytez
Copy link

ytez commented May 20, 2015

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants