From: Ben Morrow <ben@morrow.me.uk>
To: jorgemal1960@gmail.com
To: pgsql-sql@postgresql.org
Subject: Re: UPDATE query with variable number of OR conditions in WHERE
Date: Thu, 14 Mar 2013 23:58:11 +0000
Message-ID: <20130314235807.GA81164@anubis.morrow.me.uk> (raw)
In-Reply-To: <CAAY=A7-JA3iaitwjh+kYAsq0frUqBGkauwYVSSWBqz-feDAO7Q@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ben@morrow.me.uk, jorgemal1960@gmail.com
Subject: Re: UPDATE query with variable number of OR conditions in WHERE
In-Reply-To: <20130314235807.GA81164@anubis.morrow.me.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox