From: Tom Lane <tgl@sss.pgh.pa.us>
To: Victor Dobrovolsky <booby.stager@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: right way of using case-expressions in plpgsql functions
Date: Sun, 15 Oct 2023 17:15:41 -0400
Message-ID: <2124262.1697404541@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJFsatPM9D8UJ_CcupDY7iMx6dc7w74BiWhS+E4GwV8FSArKTw@mail.gmail.com>
References: <CAJFsatMhj1oX8kVcSUiTkEddk=Evh10NH9v=-Nxo8vD7xQ0mLg@mail.gmail.com>
<CAKFQuwbb4_XaC4PxVJEP+L8zWKFuBNRfz7+rQhub4TozcAjMBQ@mail.gmail.com>
<2095404.1697389696@sss.pgh.pa.us>
<CAJFsatPM9D8UJ_CcupDY7iMx6dc7w74BiWhS+E4GwV8FSArKTw@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, booby.stager@gmail.com, david.g.johnston@gmail.com
Subject: Re: right way of using case-expressions in plpgsql functions
In-Reply-To: <2124262.1697404541@sss.pgh.pa.us>
References: <CAJFsatMhj1oX8kVcSUiTkEddk=Evh10NH9v=-Nxo8vD7xQ0mLg@mail.gmail.com> <CAKFQuwbb4_XaC4PxVJEP+L8zWKFuBNRfz7+rQhub4TozcAjMBQ@mail.gmail.com> <2095404.1697389696@sss.pgh.pa.us> <CAJFsatPM9D8UJ_CcupDY7iMx6dc7w74BiWhS+E4GwV8FSArKTw@mail.gmail.com> <2124262.1697404541@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox