Re: Conditional expression in an UPDATE statement

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Conditional expression in an UPDATE statement
Date: 2013-02-07 06:41:30
Message-ID: keviaq$8bh$3@gonzo.reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 2013-02-07, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> wrote:

> Can I use a conditional expression in an UPDATE query like this:
>
> UPDATE table_1 SET
> field_1 =
> CASE WHEN (condition) THEN (COALESCE(query_1, -1))
> ELSE (COALESCE(query_1, -2))
> END
>

yesh, that should work.

--
⚂⚃ 100% natural

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bert 2013-02-12 09:38:10 upsert doesn't seem to work..
Previous Message JORGE MALDONADO 2013-02-07 01:08:05 Conditional expression in an UPDATE statement