Re: BUG #5028: CASE returns ELSE value always when type is "char" - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #5028: CASE returns ELSE value always when type is "char"
Date
Msg-id 16097.1252077321@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #5028: CASE returns ELSE value always when type is "char"  (Sam Mason <sam@samason.me.uk>)
Responses Re: BUG #5028: CASE returns ELSE value always when type is "char"  (Robert Haas <robertmhaas@gmail.com>)
Re: BUG #5028: CASE returns ELSE value always when type is "char"  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Re: BUG #5028: CASE returns ELSE value always when type is "char"  (Jeff Davis <pgsql@j-davis.com>)
List pgsql-bugs
Sam Mason <sam@samason.me.uk> writes:
> Would something like the included patch be accepted?
> [ patch to make charin() throw error for excess input ]

I remembered the reason why this idea got rejected previously.
The winning argument was that "char" should behave as nearly
as possible like the standard type char(1).  And guess what,
that truncates silently:

regression=# select 'foo'::char(1);
 bpchar
--------
 f
(1 row)

However, I think we forgot that that is only true for an explicit
coercion to char.  If you do this:

regression=# create table fool (f1 char(1));
CREATE TABLE
regression=# insert into fool values('123');
ERROR:  value too long for type character(1)

(I'm too lazy to go look up chapter and verse, but all of this is per
SQL standard.  Consistency ain't their strong point.)

I certainly don't want to have "char" emulate the misbegotten decision
to have explicit and implicit coercions behave differently.  So it
looks to me like the argument to make "char" work like char(1) doesn't
actually help us much to decide if an error should be thrown here or
not.  On the whole, throwing an error seems better from a usability
perspective.

Comments?

            regards, tom lane

PS: I would suggest that we borrow the wording and SQLSTATE of the
existing message, if we do make it throw an error.

pgsql-bugs by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: BUG #5033: Fallback using Warm Standby
Next
From: ""
Date:
Subject: BUG #5035: cast 'text' to 'name' doesnt work in plpgsql function