pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Conditional expression in an UPDATE statement
2+ messages / 2 participants
[nested] [flat]

* Conditional expression in an UPDATE statement
@ 2013-02-07 01:08  JORGE MALDONADO <jorgemal1960@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: JORGE MALDONADO @ 2013-02-07 01:08 UTC (permalink / raw)
  To: pgsql-sql

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

With respect,
Jorge Maldonado

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Conditional expression in an UPDATE statement
@ 2013-02-07 06:41  Jasen Betts <jasen@xnet.co.nz>
  parent: JORGE MALDONADO <jorgemal1960@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Jasen Betts @ 2013-02-07 06:41 UTC (permalink / raw)
  To: pgsql-sql

On 2013-02-07, JORGE MALDONADO <jorgemal1960@gmail.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



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2013-02-07 06:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-02-07 01:08 Conditional expression in an UPDATE statement JORGE MALDONADO <jorgemal1960@gmail.com>
2013-02-07 06:41 ` Jasen Betts <jasen@xnet.co.nz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox