Re: right way of using case-expressions in plpgsql functions - Mailing list pgsql-general

From Tom Lane
Subject Re: right way of using case-expressions in plpgsql functions
Date
Msg-id 2124262.1697404541@sss.pgh.pa.us
Whole thread Raw
In response to Re: right way of using case-expressions in plpgsql functions  (Victor Dobrovolsky <booby.stager@gmail.com>)
Responses Re: right way of using case-expressions in plpgsql functions
List pgsql-general
Victor Dobrovolsky <booby.stager@gmail.com> writes:
> From that - "short and dirty translation" - point of view - should I prefer
> to divide that
> $$
> Select
> case $1
> when '1'::numeric then tbl.p1
> when '2'::numeric then tbl.p2
> ...
> end as cresult
> $$

> expression into:
> $$
> ...
> if $1 = '1'::numeric then (query_1)
> elsif when '2'::numeric then (query_2)
>  ...
> end if;
> ...
> $$

Yeah, that would probably be a preferable approach if you're hoping
for significantly different query plans for the two cases.  PG does
not have the sort of run-time plan choice mechanism that you're
describing for Oracle.

            regards, tom lane



pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: right way of using case-expressions in plpgsql functions
Next
From: Victor Dobrovolsky
Date:
Subject: Re: right way of using case-expressions in plpgsql functions