Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1msrAH-0005gB-Rm for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Dec 2021 18:50:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1msrAG-0004lE-FC for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Dec 2021 18:50:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1msrAG-0004jv-6G for pgsql-bugs@lists.postgresql.org; Thu, 02 Dec 2021 18:50:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1msrAD-0007ay-Ry for pgsql-bugs@lists.postgresql.org; Thu, 02 Dec 2021 18:50:39 +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 1B2IoaXL2117702; Thu, 2 Dec 2021 13:50:36 -0500 From: Tom Lane To: "Ian R. Campbell" cc: pgsql-bugs@lists.postgresql.org Subject: Re: Inconsistent cast to "char" In-reply-to: References: Comments: In-reply-to "Ian R. Campbell" message dated "Thu, 02 Dec 2021 18:24:42 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2117700.1638471036.1@sss.pgh.pa.us> Date: Thu, 02 Dec 2021 13:50:36 -0500 Message-ID: <2117701.1638471036@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Ian R. Campbell" writes: > I noticed that the following does not produce consistent cast results: > select 1::int8::"char", 1::int4::"char", 1::int2::"char" Concretely, that gives: regression=# select 1::int8::"char", 1::int4::"char", 1::int2::"char"; char | char | char ------+------+------ 1 | \x01 | 1 (1 row) The reason for this is that there's a bespoke int4-to-"char" cast, which just produces the character with that code point; this is documented as the "char"(int) function. However, there are no such bespoke casts for int2 or int8, so those go via cast-via-I/O, much as if you were casting to/from text. The same happens with numeric, or indeed other types. One possible answer to this is to reclassify "char" as not being a member of the "string" category, so that the implicit-I/O-cast rule wouldn't be applied to it. I'm not sure if that'd have any downsides, but it seems like in principle it might be all right. "char" is so restricted that treating it as a general- purpose string type doesn't seem very sane. (Now that I look, I see that somebody thought that it'd be cool to assign category S to various special-purpose types like pg_mcv_list. That seems downright dangerous.) regards, tom lane