0

I want to find all users with Cyrillic names. How can I do it with ActiveRecord?

Non ActiveRecord solution is here: User.all.select{ |user| user.name.match(/\p{Cyrillic}/) }. Unfortunatelly regexp /\p{Cyrillic}/ doesn't work with sql.

UPDATE: from the discussion below I realize that I need solutions for Postgres and MySQL. For postgres it could be SELECT * FROM "items" WHERE (title SIMILAR TO '%[\u0410-\u044f]%')

from Find all rows using some Unicode range (such as Cyrillic characters) with PostgreSQL?

alex naumov
  • 331
  • 3
  • 9
  • Possible duplicate of https://stackoverflow.com/questions/19777720/rails-sql-regular-expression – Jagdeep Singh Jul 05 '18 at 06:50
  • @JagdeepSingh It is not a duplicate of that link definitely. Author did not ask for "how to use Regexp in SQL" at all. – Pavel Mikhailyuk Jul 05 '18 at 07:03
  • Alex, you have to add your DB in tags, because answer is DB specific. I.e. for Postgresql - https://stackoverflow.com/questions/19789604/find-all-rows-using-some-unicode-range-such-as-cyrillic-characters-with-postgr – Pavel Mikhailyuk Jul 05 '18 at 07:04
  • @PavelMikhailyuk thanks for Postgres solution. I'd like to get a not DB specific answer, which could be used for MySQL and Postgres as well ;) – alex naumov Jul 05 '18 at 09:29
  • @JagdeepSingh thanks for the link, but it's only about regexp in ActiveRecord query. I need a specific one. – alex naumov Jul 05 '18 at 09:31
  • Alex, there is no regexp standard in SQL. Each DB implements it with its own keywords and (even worse) own regexp libraries https://stackoverflow.com/questions/18780194/how-to-regex-in-a-sql-query – Pavel Mikhailyuk Jul 05 '18 at 09:40
  • And even solution from Postrge example is not perfect, because it depends on string data `encoding`, which can differs. – Pavel Mikhailyuk Jul 05 '18 at 09:42

0 Answers0