I'm trying to conditionally match against a REGEX. If the REGEX is blank, it is a match, otherwise, match against the REGEX. Currently I have tried the mySQL IF function, CASE statement, and logical operators with no success. This is on MySQL 5.6.12. The error I am getting is:
ERROR 1139 (42000): Got error 'empty (sub)expression' from regexp
Here are some statements showing my issue.
SET @test = '';
SELECT (@test = '' || ('abc123' REGEXP @test)) AS matches;
SELECT (true || ('abc123' REGEXP @test)) AS matches;
SELECT IF(true, true, 'abc123' REGEXP @test) AS matches;
SELECT (CASE WHEN true THEN true ELSE 'abc123' REGEXP @test END) AS matches;
I would have expected the operators precedence order to return true in all these statements. Is there documentation I missed? Any help is appreciated.
ORin place of the disjunctive||, and, in SQL dialects offering it, theCONCATfunction in place of the concatenative||.