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

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: BUG #5028: CASE returns ELSE value always when type is "char"
Дата
Msg-id 20090901164925.GK5407@samason.me.uk
обсуждение исходный текст
Ответ на BUG #5028: CASE returns ELSE value always when type is "char"  ("Joseph Shraibman" <jks@selectacast.net>)
Ответы Re: BUG #5028: CASE returns ELSE value always when type is "char"
Re: BUG #5028: CASE returns ELSE value always when type is "char"
Список pgsql-bugs
On Tue, Sep 01, 2009 at 04:36:25PM +0000, Joseph Shraibman wrote:
> Description:        CASE returns ELSE value always when type is "char"

I think it's just silently truncating the literal to a single character.

> [local]:playpen=> select c.relkind, CASE c.relkind WHEN 'r' THEN 'table'
> WHEN 'v' THEN 'view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's'
> THEN 'special' WHEN 'c' THEN 'composite type' WHEN 't' THEN 'toast' ELSE
> c.relkind
> playpen->  END from (select 'r'::"char" AS relkind) c;
>  relkind | relkind
> ---------+---------
>  r       | t

Here, 'r' maps to the "char" literal 'table' which PG interprets as the
value 't'--i.e. PG silently chops of the 'able'.  The bug would seem to
be in your code, but PG could maybe throw an error to tell you this is
what is happening?

A possible fix would be to have your ELSE clause as:

  c.relkind::text

As that way the other branches would be interpreted as text and they
wouldn't be getting chopped off along the way.

--
  Sam  http://samason.me.uk/

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: BUG #5025: Aggregate function with subquery in 8.3 and 8.4.
Следующее
От: Joseph Shraibman
Дата:
Сообщение: Re: BUG #5028: CASE returns ELSE value always when type is "char"