From: | David Hartwig <daybee(at)bellatlantic(dot)net> |
---|---|
To: | Kevin Heflin <kheflin(at)shreve(dot)net> |
Cc: | "PGSQL-General (E-mail)" <pgsql-general(at)postgreSQL(dot)org> |
Subject: | Re: [GENERAL] select LIKE |
Date: | 1998-09-03 23:53:37 |
Message-ID: | 35EF2C00.834644F0@bellatlantic.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Kevin Heflin wrote:
> I have a rolodex database in Postgres.
> I want allow searches by "name" and/or company from a web page.
> I'm using PHP/Apache to connect with postgres
>
> I tried something like:
>
> select * from rolodex where name LIKE '%$name%'
>
> First question: is there a way to do this that is NOT case sensitive?
>
Use the case insensitive regular expression operator.
select * from rolodex where name ~* '.*$name.*'
I'm not sure if you need either of the ".*" wild card pairs to match zero or
more of any character.
>
> also I wanted to allow for searches of name and/or company..
>
> but if a user enters info in "name" and not "company" it returns back no
> items found.
>
> I'm using '%$company%' (percent signs on both sides so that the user can
> take a short guess. However if the user doesn't input anything for
> company, this returns no items.. if I have the variable set up as:
>
> '%$company' with only the percent sign in the beginning, it will work o.k.
I'm not sure what LIKE '%%' means. It may be taken as a literal "%" and not
as a wild card. Try removing the entire condition if $company is null. You
will get better performance, if it matters.
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 1998-09-04 01:02:21 | Re: [GENERAL] big numbers |
Previous Message | Kevin Heflin | 1998-09-03 22:21:02 | select LIKE |