Whats the most efficient way to search for a sub string in SQLite?
I'm looking at the LIKE operator.
Do I have the right idea? Has this worked well for you?
http://www.sqlite.org/lang_expr.html
Thank You.
Join Stack Overflow to learn, share knowledge, and build your career.
Whats the most efficient way to search for a sub string in SQLite?
I'm looking at the LIKE operator.
Do I have the right idea? Has this worked well for you?
http://www.sqlite.org/lang_expr.html
Thank You.
Yepper, use Like. Select id from sometable where name like '%omm%'
would return any row that had 'omm' anywhere in the name column.
You can use LIKE
, but it gets really slow if the pattern you're searching for starts with '%'
-- i.e., if the substring you're looking for isn't necessarily at the beginning of the field.
If you need to do such searches, consider using FTS3, which makes full-text searching considerably more efficient.
If you need to do such searches
do you mean pattern starts at the beginning of the field or does not start at the beginning? Because fts in SQLite doesn't support suffix matches.
– Jason
Mar 13 '19 at 0:59
Years have passed since the question was asked and answered and in 2012 SQLite version 3.7.15 introduced a function instr( string, substring)
- returns the location of a substring in a string, 0 if not found. (https://www.techonthenet.com/sqlite/functions/instr.php)
sqlite> SELECT instr('TechOnTheNet.com', 'T');
Result: 1
I have not benchmarked against LIKE
, but IMHO could be faster.