From: | "Robert B(dot) Easter" <reaster(at)comptechnews(dot)com> |
---|---|
To: | Peter Eisentraut <peter_e(at)gmx(dot)net>, Albert REINER <areiner(at)tph(dot)tuwien(dot)ac(dot)at> |
Cc: | PostgreSQL-SQL <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Documentation for CASE |
Date: | 2000-12-16 23:01:49 |
Message-ID: | 00121618014902.22968@comptechnews |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)comptechnews(dot)com ---------
- CompTechNews Message Board http://www.comptechnews.com/ -
- CompTechServ Tech Services http://www.comptechserv.com/ -
---------- http://www.comptechnews.com/~reaster/ ------------
From | Date | Subject | |
---|---|---|---|
Next Message | Albert REINER | 2000-12-17 14:56:59 | Re: Documentation for CASE |
Previous Message | Peter Eisentraut | 2000-12-16 17:39:14 | Re: Documentation for CASE |