Thread: Bug #945: RFE: Update table SET CASE...END=foo WHERE...

Bug #945: RFE: Update table SET CASE...END=foo WHERE...

From
pgsql-bugs@postgresql.org
Date:
Richard Neill (postgresql@richardneill.org) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
RFE: Update table SET CASE...END=foo WHERE...

Long Description
It would be *really* nice to be able to determine the column which should be updated by a case statement. Eg:

UPDATE tbl_foo SET
CASE WHEN column1='bar' THEN column3 WHEN column2='baz' THEN column4 END
='wibble' WHERE column5='flibble';

i.e. depending on the values of column1/column2, the value wibble is assigned to column3 or column4

If this isn't possible, may I at least suggest a note in the manual to this effect, and with the workaround.

[Another thing to add to the manual in 6.12 is that a CASE statement inside a SELECT may be used to determine which
column'scontents to  
return]

I'm using version 7.2.2

Sample Code
UPDATE tbl_messages set CASE WHEN idto=8 THEN recipientread WHEN idfrom=8 THEN senderread END ='true' WHERE id=1910787;

This is the SQL I actually want to execute...and can't. Thanks for your help.

No file was uploaded with this report