From: | Victor Dobrovolsky <booby(dot)stager(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: right way of using case-expressions in plpgsql functions |
Date: | 2023-10-15 21:53:14 |
Message-ID: | CAJFsatMH0O=3u2jCkBu6sj5AOGY4-enjKqZFsBHVeYs=pgv7cw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>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(at)sss(dot)pgh(dot)pa(dot)us>:
> Victor Dobrovolsky <booby(dot)stager(at)gmail(dot)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
>
From | Date | Subject | |
---|---|---|---|
Next Message | Victor Dobrovolsky | 2023-10-15 21:54:22 | Re: right way of using case-expressions in plpgsql functions |
Previous Message | Tom Lane | 2023-10-15 21:15:41 | Re: right way of using case-expressions in plpgsql functions |