From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-sql@postgreSQL.org
Subject: Does SQL have anything like C's conditional expression?
Date: Mon, 20 Jul 1998 16:01:33 -0400
Message-ID: <22075.900964893@sss.pgh.pa.us> (raw)
I have the following problem: given a specific record in a table
(identified by OID, in my case), always update field A to a new value,
and update field B to a new value only if field C contains 'OK'.
This is easy to do in two queries, say
UPDATE table SET fieldA = valueA WHERE oid = something;
UPDATE table SET fieldB = valueB WHERE oid = something AND fieldC = 'OK';
For speed reasons, I'm wondering if it can be done in one query.
It could be done with something like a C conditional expression:
UPDATE table SET
fieldA = valueA,
fieldB = (fieldC = 'OK') ? valueB : fieldB
WHERE oid = something;
but SQL doesn't seem to have that concept. Can anyone suggest
a fast way to do what I need to do?
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: Does SQL have anything like C's conditional expression?
In-Reply-To: <22075.900964893@sss.pgh.pa.us>
References: <22075.900964893@sss.pgh.pa.us>
* 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