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 1sjSlF-000wIX-5l for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Aug 2024 00:11:37 +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 1sjSlD-00CJKJ-1C for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Aug 2024 00:11:35 +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 1sjSlC-00CJK3-Oh for pgsql-bugs@lists.postgresql.org; Thu, 29 Aug 2024 00:11:35 +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 1sjSl8-001zxC-OJ for pgsql-bugs@lists.postgresql.org; Thu, 29 Aug 2024 00:11:34 +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 47T0BSmw3501447; Wed, 28 Aug 2024 20:11:28 -0400 From: Tom Lane To: =?UTF-8?Q?Francisco_J=2E_Ossand=C3=B3n?= cc: Andrew Dunstan , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18594: CASE WHEN ELSE failing to return the expected output when the same colum is used in WHEN and ELSE In-reply-to: References: <18594-af265c6988d431d8@postgresql.org> <0838f16a-8b3d-4c39-9ad8-5d27791e9dec@dunslane.net> Comments: In-reply-to =?UTF-8?Q?Francisco_J=2E_Ossand=C3=B3n?= message dated "Wed, 28 Aug 2024 20:02:50 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3501445.1724890288.1@sss.pgh.pa.us> Date: Wed, 28 Aug 2024 20:11:28 -0400 Message-ID: <3501446.1724890288@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk =?UTF-8?Q?Francisco_J=2E_Ossand=C3=B3n?= writes: > So is the ELSE column hijacking the data type of the whole expression? It's the only CASE result that is supplying a definite type at all. But see https://www.postgresql.org/docs/current/typeconv-union-case.html particularly the footnote to the bit about "Select the first non-unknown input type as the candidate type, then consider each other non-unknown input type, left to right." The WHEN clauses have exactly nothing to do with the result type of the CASE: it's the THEN and ELSE clauses that supply the result. regards, tom lane