Re: BUG #5028: CASE returns ELSE value always when type is "char"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sam Mason <sam(at)samason(dot)me(dot)uk>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5028: CASE returns ELSE value always when type is "char"
Date: 2009-09-04 15:15:21
Message-ID: 16097.1252077321@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Sam Mason <sam(at)samason(dot)me(dot)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.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Robert Haas 2009-09-04 15:50:25 Re: BUG #5028: CASE returns ELSE value always when type is "char"
Previous Message Dennis Seran 2009-09-04 14:15:23 BUG #5036: Advisory locks have unexpected behavior