From: Robert B. Easter <reaster@comptechnews.com>
To: Peter Eisentraut <peter_e@gmx.net>
To: Albert REINER <areiner@tph.tuwien.ac.at>
Cc: PostgreSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: Documentation for CASE
Date: Sat, 16 Dec 2000 18:01:49 -0500
Message-ID: <00121618014902.22968@comptechnews> (raw)
In-Reply-To: <Pine.LNX.4.30.0012161838290.976-100000@peter.localdomain>
References: <Pine.LNX.4.30.0012161838290.976-100000@peter.localdomain>
Here are some examples of CASE used in PL/pgSQL for both an UPDATE and an
assignment:
NEW.tscore := round( (NEW.treply_scores + (CASE WHEN
NEW.scored = ''f'' THEN 0 ELSE NEW.score END) )::FLOAT / (NEW.treplies + 1) );
END IF;
IF NEW.tscore != OLD.tscore OR NEW.score != OLD.score THEN
IF OLD.scored = ''f'' THEN
OLD.score := 0;
END IF;
IF NEW.scored = ''f'' THEN
NEW.score := 0;
END IF;
UPDATE users SET score = score
- (CASE WHEN OLD.tscore >
OLD.score THEN OLD.tscore ELSE OLD.score END)
+ (CASE WHEN NEW.tscore >
NEW.score THEN NEW.tscore ELSE NEW.score END)
WHERE id = NEW.users_id;
IF NEW.scored = ''f'' THEN
Kind of cool the way PostgreSQL functions and some other SQL language
elements etc can be used in assignments too.
On Saturday 16 December 2000 12:39, Peter Eisentraut wrote:
> Albert REINER writes:
> > I think that the documentation for CASE is not very clear:
>
> Maybe you will like this better (from upcoming 7.1):
>
> http://www.postgresql.org/devel-corner/docs/postgres/functions-conditional.
>htm
--
-------- Robert B. Easter reaster@comptechnews.com ---------
- CompTechNews Message Board http://www.comptechnews.com/ -
- CompTechServ Tech Services http://www.comptechserv.com/ -
---------- http://www.comptechnews.com/~reaster/ ------------
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: reaster@comptechnews.com, peter_e@gmx.net, areiner@tph.tuwien.ac.at
Subject: Re: Documentation for CASE
In-Reply-To: <00121618014902.22968@comptechnews>
References: <Pine.LNX.4.30.0012161838290.976-100000@peter.localdomain> <00121618014902.22968@comptechnews>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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