Answer the question
In order to leave comments, you need to log in
Why does the error "invalid regular expression: quantifier operand invalid" occur?
Hello. There is a filter table for books.
create table filter
(
"id" serial PRIMARY KEY,
"user_id" serial REFERENCES public.user (id) ON DELETE CASCADE,
"keywords" text []
);
self.create = function (obj) {
return db.query(`INSERT INTO public.filter (user_id, keywords)
VALUES ($(userId), $(keywords)) RETURNING id;`, obj);
};
SELECT * FROM public.filter WHERE
LOWER('Some long string from a book') ~ ANY(public.filter.keywords);
ERROR: ОШИБКА: неверное регулярное выражение: quantifier operand invalid
SQL state: 2201B
Answer the question
In order to leave comments, you need to log in
Try escaping special characters (pluses in the word "c++")
To use a literal instance of a special character in a regular expression, precede it by two backslash (\) characters. The MySQL parser interprets one of the backslashes, and the regular expression library interprets the other. For example, to match the string 1+2 that contains the special + character, only the last of the following regular expressions is the correct one:
mysql> SELECT REGEXP_LIKE('1+2', '1+2'); -> 0
mysql> SELECT REGEXP_LIKE('1+2', '1\+2'); -> 0
mysql> SELECT REGEXP_LIKE('1+2', '1\\+2'); -> 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question