Escape field in LIKE request

Next query:

SELECT `att`.`val` FROM `att` WHERE NOT (`att`.`val` LIKE `att`.`val`);

      

Shouldn't return anything, right?

But it returns all val

that have a backslash in them.

How do I make it return nothing?

val

is a field varchar(1024)

(not primary, not empty).

This is of course a useless query, but it is a simplified version of another query that does not work for the same reason.

I am using mysql 5.6.20.

Thank!

EDIT:

I want to avoid every character that needs escaping in order for the query to work as intended. Not just a backslash.

+3


source to share


1 answer


Try changing the condition to:

WHERE NOT (`att`.`val` LIKE replace(`att`.`val`,'\\','\\\\'))

      



- this replaces single backslashes with double backslashes in val

, so that instead of acting as escape characters, they are treated as literal backslashes by an expression like

. (The first backslash escapes the second.)

+2


source







All Articles