I have a table with a column field that has values like Samsung Phone.
My question is how can I get this row if I search for a string \"Samsung\" or \"phone
You can use a regular expression for this:
where title ~* '(\mphone\M)|(\msamsung\M)'
The above only returns values where phone or samsung are complete words. The regex modifiers\m and \M make the pattern only match for whole words.
The regex operator ~* makes this case-insensitive. The above expression would return Samsung Phone or Google Phone but not Sam's House.
If you want to add more words, just add them using the "or" operator |
where title ~* '(\mphone\M)|(\msamsung\M)|(\mbhat\M)'
Note that this kind of search is not going t1o be super-fast. Regular expressions are expensive they cannot make use of any index.