LIKE operator

Поиск
Список
Период
Сортировка
От PostgreSQL
Тема LIKE operator
Дата
Msg-id 00b101be8dc4$652e6b80$0300000a@cpqivx-2
обсуждение исходный текст
Ответы Re: [GENERAL] LIKE operator  (Bruce Momjian <maillist@candle.pha.pa.us>)
Список pgsql-general
Hi,

With mSQL I used to perform queries like below from within PHP:

  select field1, field2 from table1 where field1 like '%$some_variable%'

where the '%' in the LIKE clause matches 0 or more characters of any value.
That is, the query above would match the strings that contain
'$some_variable' OR any string if $some_variable is empty.

For example: my table has two rows with the first record containing
field1='abc' and the second record containing field1='cde'.

  If '$some_variable' is empty, then my query would return both rows.
  If $some_variable='bc', then the query would return only the row where
field1='abc'.

With PostgreSQL I experience the following:

  If '$some_variable' is empty, then my query returns *nothing*.
  If $some_variable='bc', then the query would return only the row where
field1='abc'.

As the value of '$some_variable' is to be filled by some user while posting
a form, I don't know in advance if it is going to be empty or not.

How can I make the query results to be exactly as with mSQL without having
to alter my query 'throwing out' every part of the 'where' clause where
'$some_variable' is empty?

TIA,

Paulo
pparola@brazilinfo.com



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

Предыдущее
От: "Paulo Parola"
Дата:
Сообщение: LIKE operator
Следующее
От: JT Kirkpatrick
Дата:
Сообщение: win98 odbc problem? some other limitation?