Using case in an update statement ? - Mailing list pgsql-novice

From Peter Alberer
Subject Using case in an update statement ?
Date
Msg-id 001001c20bd0$d0566060$5be0d089@ekelhardt
Whole thread Raw
Responses Re: Using case in an update statement ?
Re: Using case in an update statement ?
List 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'');

pgsql-novice by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: date conversions
Next
From: "Josh Berkus"
Date:
Subject: Re: Using case in an update statement ?