Re: Question - Query based on WHERE OR

Поиск
Список
Период
Сортировка
Искать
От
John D. Burger
Тема
Re: Question - Query based on WHERE OR
Дата
Msg-id
34BFD047-9BE6-4841-A174-01B410A6F436@mitre.org
Ответ на
Список
Дерево обсуждения
Question - Query based on WHERE OR "Mike Poe" <trolling4dollars@gmail.com>
Re: Question - Query based on WHERE OR Ragnar <gnari@hive.is>
Re: Question - Query based on WHERE OR "John D. Burger" <john@mitre.org>
Re: Question - Query based on WHERE OR SCassidy@overlandstorage.com
Mike Poe wrote:

> SELECT foo, baz, bar FROM public.table WHERE lastname ~*  
> '$lastname' OR ssn='$ssn'"
>
> I need to leave the last name a wildcard in case someone enters a  
> partial name, lower case / upper case, etc.
> I want the SSN to match exactly if they search by that.
> The way it's written, if I enter nothing for the last name, it  
> returns all rows, regardless of what I enter for the ssn.
> I understand why it happens, but what can I do to return the  
> desired results?

How about:

SELECT foo, baz, bar FROM public.table
   WHERE ('$lastname' != '' and lastname ~* '$lastname') OR ssn='$ssn'";

Or perhaps some more general condition for "empty" lastname parameters.

- John Burger
   MITRE
В списке pgsql-general по дате отправления
От: Simon Riggs
Дата:
Сообщение: Re: pg_standby testing notes
От: Andrew Dunstan
Дата:
FAQ