Manufacturer
==========================
id name
--------------------------
1 Company Inc.
2 Google Test.
3 3M (UNITY) USA. INC.
4 CE EE
Say, I have a string 'Google Test. 1257 SCS RANDOM 31233DD' and I want to find all rows in table manufacturer
where ht name
is part of the given string:
SELECT * FROM manufacturer
WHERE 'Google Test. 1257 SCS RANDOM 31233DD' ILIKE '%' || name || '%'
Correctly returns:
id name
--------------------------
2 Google Test.
But when I do:
SELECT * FROM manufacturer
WHERE '3dad QTICE EEN ' ILIKE '%' || name || '%'
it returns:
id name
--------------------------
4 CE EE
I don't want partial matches like this. The name
shall not match in the middle of a word. I tried substring()
:
SELECT * from manufacturer
WHERE SUBSTRING('Google Test. 1257 SCS RANDOM 31233DD' from name) != '';
But I get:
ERROR: invalid regular expression: quantifier operand invalid
Unfortunately I don't have the exact spec to go off since I am querying this off external db. But from what I have seen, column is varchar(256)
. All values are upper cased and use plain spaces. All start with either character or number and end with either number, char, or special character. Ex: 'CLEVLAND DRILL (GREEN)'. There are special characters in the value, such as ,.()&/
I am not really looking for efficiency as long as it doesn't take over 50ms to do one query.
As of right now, there are about 10000+ entries but it could def grow over time.