Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qs8Sl-006uLF-TQ for pgsql-general@arkaria.postgresql.org; Sun, 15 Oct 2023 21:15:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qs8Sj-00CsQP-E5 for pgsql-general@arkaria.postgresql.org; Sun, 15 Oct 2023 21:15:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qs8Sj-00CsPc-3N for pgsql-general@lists.postgresql.org; Sun, 15 Oct 2023 21:15:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qs8Sb-000qeo-Of for pgsql-general@lists.postgresql.org; Sun, 15 Oct 2023 21:15:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 39FLFfL22124263; Sun, 15 Oct 2023 17:15:41 -0400 From: Tom Lane To: Victor Dobrovolsky cc: "David G. Johnston" , "pgsql-general@lists.postgresql.org" Subject: Re: right way of using case-expressions in plpgsql functions In-reply-to: References: <2095404.1697389696@sss.pgh.pa.us> Comments: In-reply-to Victor Dobrovolsky message dated "Sun, 15 Oct 2023 23:24:27 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2124261.1697404541.1@sss.pgh.pa.us> Date: Sun, 15 Oct 2023 17:15:41 -0400 Message-ID: <2124262.1697404541@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Victor Dobrovolsky 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