Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6]) by hub.org (8.8.8/8.7.5) with ESMTP id QAA17657 for ; Mon, 20 Jul 1998 16:01:40 -0400 (EDT) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id QAA22078 for ; Mon, 20 Jul 1998 16:01:33 -0400 (EDT) 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> From: Tom Lane 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