Using case in an update statement ?

From: "Peter Alberer" <peter(at)alberer(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Using case in an update statement ?
Date: 2002-06-04 14:04:59
Message-ID: 001001c20bd0$d0566060$5be0d089@ekelhardt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

I would like to change some rows in a table to two different values
depending on the current value.
The value of the column "status" should be changed to ''CLOSED_SUCC''
when its current value is ''OPEN_SUCC'' and it should be ''CLOSED_FAIL''
when the current value is ''OPEN_FAIL''. Of course I could write two
statements, but can it be done in one statement ?

I tried to do it with "case" but that failed.

update lr_object_usage set status = (case when status = ''OPEN_SUCC''
then ''CLOSED_SUCC'' when status = ''OPEN_FAIL'' then ''CLOSED_FAIL'');

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message mila boldareva 2002-06-04 14:16:04 V1 function calls
Previous Message Oliver Elphick 2002-06-04 13:18:45 Re: Question on joining tables