pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ian R. Campbell <ian.campbell@thepathcentral.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Inconsistent cast to "char"
Date: Thu, 02 Dec 2021 13:50:36 -0500
Message-ID: <2117701.1638471036@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOC8YUcXymCMpC5d=7JvcwyjXPTT00WeebOM3UqTBreOD1N9hw@mail.gmail.com>
References: <CAOC8YUcXymCMpC5d=7JvcwyjXPTT00WeebOM3UqTBreOD1N9hw@mail.gmail.com>

"Ian R. Campbell" <ian.campbell@thepathcentral.com> 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





view thread (5+ messages)  latest in thread

Message-ID: <2117701.1638471036@sss.pgh.pa.us>
Permalink:  ../2117701.1638471036@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2117701.1638471036@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ian.campbell@thepathcentral.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: Inconsistent cast to "char"
  In-Reply-To: <2117701.1638471036@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