I have a postgresql database with a users table, where each user has a name (in unicode). I'd like to find all users whose name contains at least one Hebrew character. I've thought using regex, e.g.
select * from users
where name ~ '[א-ת]';
Is there a more efficient approach than the regex? I have a B-tree index on the names column.
Update
Using the different indices with the pg_trgm
module as suggested by @FuzzyTree
B-tree GIST GIN
user 0.04 0.04 0.03
sys 0.02 0.04 0.01
total 0.06 0.08 0.04
Regarding disk size, the GIN index is 0.2x of the GIST one, and 0.8x of the B-tree. So, we have a winner here, at least for my use case. YMMV (e.g. I haven't benchmarked index creation and update). Version: postgres 9.6.