Search Postgresql Archives

Re: Using case expressions in update set clause

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Chris Velevitch" <chris.velevitch@xxxxxxxxx> writes:

> I just want to clarify that the following will always behave the way I
> think it's supposed to behave:-
>
>      update  tableA
>      set       date_field = case when date_field is null then some_date
>                                           else date_field end;
>
> If the current value of date_field for the current record is null then
> set the date_field with some_date value otherwise keep the current
> value of date_field.

That's correct. In this case you could also do it with 
 set date_field = coalesce(date_field, some_date)

-- 
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux