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

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <pgsql-bugs(at)postgresql(dot)org>,"Sam Mason" <sam(at)samason(dot)me(dot)uk>
Subject: Re: BUG #5028: CASE returns ELSE value always when type is "char"
Date: 2009-09-04 17:26:19
Message-ID: 4AA1076B020000250002AAD1@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff Davis 2009-09-04 17:53:53 Re: BUG #5028: CASE returns ELSE value always when type is "char"
Previous Message Alvaro Herrera 2009-09-04 17:23:06 Re: BUG #5035: cast 'text' to 'name' doesnt work in plpgsql function