Search Postgresql Archives

Re: right way of using case-expressions in plpgsql functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>Yeah, that would probably be a preferable approach if you're hoping
>for significantly different query plans for the two cases.

Thank you. 
My goal is to find out some basic rules that could help me to navigate issues like this.
Regarding generalized plans in general, and the use of the case-expressions in particular.


пн, 16 окт. 2023 г. в 00:15, Tom Lane <tgl@xxxxxxxxxxxxx>:
Victor Dobrovolsky <booby.stager@xxxxxxxxx> 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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux