Re: Function in selection?

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Function in selection?
Date: 2003-03-13 22:36:48
Message-ID: 3E710800.72835047@nsd.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

There is no need for the assignment in the then clause.
Ie. THEN cena=cenaeur ... should be THEN cenaeur ...
and THEN cenaeur=cena ... should be THEN cena ...
as:
BTW, the <>0 part is redondant.

SELECT CASE WHEN cena=0 THEN
cenaeur*(SELECT eur FROM devizni ORDER BY eur OFFSET 20 LIMIT 1)
ELSE cena END AS cena,
CASE WHEN cenaeur=0 THEN
cena/(SELECT eur FROM devizni ORDER BY eur OFFSET 20 LIMIT 1)
ELSE cenaeur END AS cena_eur
from oglasi
ORDER BY posr, id_regije;

"Dousak May (Phoebus Apollonus)" wrote:
>
> One more problem :)
>
> I wrote my tables and variables and it looks like that:
>
> SELECT CASE WHEN cena=0 AND cenaeur<>0 THEN cena=cenaeur
> *(SELECT eur FROM devizni ORDER BY eur OFFSET 20 LIMIT 1)
> ELSE cena END AS cena, CASE WHEN cenaeur=0 AND cena<>0
> THEN cenaeur=cena/(SELECT eur FROM devizni ORDER BY eur
> OFFSET 20 LIMIT 1) ELSE cenaeur END AS cena_eur from oglasi
> ORDER BY posr, id_regije;
>
> cena, cenaeur and eur are all double precision.
>
> When I try to execute it, I get following error:
>
> ERROR: CASE types "float8" and "bool" not matched
>
> I have no boolean in neither table... ok, comparision is binary,
> but why do I get that error?
> What can I do to make it work? :/
>
> Tnx,
>
> May
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom 2003-03-13 22:58:14 Having an optional foreign key (ie. sometimes NULL) ?
Previous Message scott.marlowe 2003-03-13 22:35:23 Re: PL/Java (was: stored procedures)