Обсуждение: Wildcard queries?

Поиск
Список
Период
Сортировка

Wildcard queries?

От
James Hall
Дата:
Hello,

I am trying to do a wildcard search on a table, for example:

I have a table - info - that has a text field - business_name.
One value in that field is Demo Inc.

My question is can I execute a query that would search that field for demo*?
Something to the effect of "SELECT * FROM info WHERE business_name LIKE
'demo*';
and return Demo Inc.?


Thanks in advance for any assistance, and for going easy on a newbie. ; )

Jim Hall

Re: Wildcard queries?

От
harrold@sage.che.pitt.edu
Дата:
Sometime in August James Hall assaulted keyboard and produced...

|Hello,
|
|I am trying to do a wildcard search on a table, for example:
|
|I have a table - info - that has a text field - business_name.
|One value in that field is Demo Inc.
|
|My question is can I execute a query that would search that field for demo*?
|Something to the effect of "SELECT * FROM info WHERE business_name LIKE
|'demo*';
|and return Demo Inc.?
|


if you used the ~* operator (or maybe it's *~) that will do a case
insensitive search. if you are looking for words starting with demo you
might want to try  ' demo'. so it would be something like this:

select * from info where business_name ~* ' demo';

this would miss any fields that had new lines that start with demo. i dont
know if there is a character that represents the beginning of a line. in
most applications (in unix that is) the ^ character matches the beginning
of the line and the $ character matches the end.

assuming that postgres understands this a query like:

select * from info where business_name ~* '^demo';

might match any line starting with demo. to get all newwords starting with
demo (case insensitive)

select * from info where business_name ~* '^demo' OR business_name ~* '
demo';

you will have to check the manual about identifiers of the beginning and
end of lines.

--
john
There is no operating system but linux and linus is its kernel maintainer.