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

From Kevin Grittner
Subject Re: BUG #5028: CASE returns ELSE value always when type is "char"
Date
Msg-id 4AA1076B020000250002AAD1@gw.wicourts.gov
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"  (Sam Mason <sam@samason.me.uk>)
List pgsql-bugs
Sam Mason <sam@samason.me.uk> wrote:

> you seem to be wanting in-memory representations of "string like
> types" to all use the same representation and only use the actual
> types when saving to/from disk.

Doing so when actually assigning to *something* of the more specific
type would probably be better.  In my view, that's not happening here;
although I see that the code currently doesn't recognize the
difference.

>> test=# select case when true then 'xxx' else 'a'::"char" end from
t;
>>  case
>> ------
>>  x
>> (1 row)
>
> With the patch I gave, or something like it, this would throw an
> error because 'xxx' is being used to initialize a value of "char"
> type.

As I read the semantics of the CASE predicate, it returns one of the
given values.  'x' is not one of the given values, regardless of type.
I don't think an error is the right thing, I think returning the
specified value is the right thing.  I don't think it's a good thing
that the type system decides that the result type for this case
predicate is "char" and that 'xxx' needs to be coerced to that type.

-Kevin

pgsql-bugs by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsql function
Next
From: Jeff Davis
Date:
Subject: Re: BUG #5028: CASE returns ELSE value always when type is "char"