javascriptmysqlrlike

Use RLIKE in Mysql - with empty or all Values


Is there any way to use RLiKE in Mysql in order to get all records?

I use this script:

SELECT DISTINCT day FROM gestionsaasco WHERE month RLIKE '';

But this is the server answer:

Got error 'empty (sub)expression' from regexp

Note: I'm not use "like '%%', because there are more than 8 filers and each one could be many values in my array, so I convert the array into string in order to use it in mysql, like this:

const DataMonth  = req.body.data.month.map(value => value.value);
const month = DataMonth.toString().replace(",","|");
/* DataMonth looks like [05,06,07] */
/* month looks like 05|06|07 */

const months = await pool.query('SELECT DISTINCT day FROM gestionsaasco WHERE month RLIKE ?',[year])

Solution

  • RLIKE is looking for a regular expression

    Empty string is '^$' (no text between start and end

    And all text '.*'