Re: UPDATE query with variable number of OR conditions in WHERE

Поиск
Список
Период
Сортировка
От Ben Morrow
Тема Re: UPDATE query with variable number of OR conditions in WHERE
Дата
Msg-id 20130314235807.GA81164@anubis.morrow.me.uk
обсуждение исходный текст
Ответ на UPDATE query with variable number of OR conditions in WHERE  (JORGE MALDONADO <jorgemal1960@gmail.com>)
Ответы Re: UPDATE query with variable number of OR conditions in WHERE  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Quoth jorgemal1960@gmail.com (JORGE MALDONADO):
> 
> I am building an UPDATE query at run-time and one of the fields I want to
> include in the WHERE condition may repeat several times, I do not know how
> many.
> 
> UPDATE table1
> SET field1 = "some value"
> WHERE (field2 = value_1 OR field2 = value_2 OR .....OR field2 = value_n)
> 
> I build such a query using a programming language and, after that, I
> execute it. Is this a good approach to build such a query?

You can use IN for this:
   UPDATE table1   SET field1 = "some value"   WHERE field2 IN (value_1, value_2, ...);

Ben




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

Предыдущее
От: JORGE MALDONADO
Дата:
Сообщение: UPDATE query with variable number of OR conditions in WHERE
Следующее
От: Tom Lane
Дата:
Сообщение: Re: UPDATE query with variable number of OR conditions in WHERE