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 1tkD60-001MSw-5I for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Feb 2025 02:12:24 +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 1tkD5y-005lNY-4e for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Feb 2025 02:12:22 +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 1tkD5x-005lNQ-SP for pgsql-bugs@lists.postgresql.org; Tue, 18 Feb 2025 02:12:21 +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.96) (envelope-from ) id 1tkD5v-001TFY-2X for pgsql-bugs@lists.postgresql.org; Tue, 18 Feb 2025 02:12:21 +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 51I2CIBx1149961; Mon, 17 Feb 2025 21:12:18 -0500 From: Tom Lane To: "David G. Johnston" cc: Chris BSomething , PostgreSQL Bug List 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> <3501446.1724890288@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Mon, 17 Feb 2025 15:31:22 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1149959.1739844738.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 17 Feb 2025 21:12:18 -0500 Message-ID: <1149960.1739844738@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Wed, Jan 22, 2025 at 3:00 AM Chris BSomething > wrote: >> ... should there not be a new rule, >> something like considering if the unknown types can be converted, then >> notice that a long string can't be converted to a char, because it won't >> fit? And then fail with an interesting error? > Do you have an example demonstrating this new rule? I'm doubting this > resolution logic goes into that much depth regarding the semantics of each > type. It is implied that even if an implicit cast exists from type A to > type B that actual values of type A may fail during the casting process to > make them type B. That would be the interesting error you'd end up seeing > - but from the type casting/input system, not the type resolution one. Yeah. We document somewhere that the contents of a literal string are *not* considered while deciding what type it should be taken as; thus, the possibility of a casting failure is not part of the rules. I think such a rule would be pretty dangerous, even if we could implement it easily. As an example, if you entered something you meant as a timestamp, but you fat-fingered the punctuation or something, it'd likely fall back to being considered just "text", potentially silently changing the semantics of the expression. We had a lot of trouble with that sort of behavior back when the system had a lot of implicit casts to text. We got rid of (most of) those in 8.3 or thereabouts, and it made the semantics generally a lot safer. regards, tom lane