Re: select where true, or select where input = '$var'

Поиск
Список
Период
Сортировка
От Paul Jungwirth
Тема Re: select where true, or select where input = '$var'
Дата
Msg-id 54E64CEA.3080407@illuminatedcomputing.com
обсуждение исходный текст
Ответ на select where true, or select where input = '$var'  (zach cruise <zachc1980@gmail.com>)
Список pgsql-general
 > i want to select based on input, but if input is not provided or if
 > input is empty, then i want to select all rows.

I think you can just use OR:

SELECT  *
FROM    table
WHERE   (input = '' OR input = ?)

This is assuming that `input` is a column in your table and ? is the
user input, based on the query you provided. But are you sure that's
what you mean?

Also, if the `input` column can contain nulls you might also want:

SELECT  *
FROM    table
WHERE   (input IS NULL OR input = '' OR input = ?)

Paul



В списке pgsql-general по дате отправления:

Предыдущее
От: John R Pierce
Дата:
Сообщение: Re: select where true, or select where input = '$var'
Следующее
От: Chris Mair
Дата:
Сообщение: Re: rollback in C functions