Re: possible bug with group by?

Поиск
Список
Период
Сортировка
От Joseph Shraibman
Тема Re: possible bug with group by?
Дата
Msg-id 392C63FF.F0186004@selectacast.net
обсуждение исходный текст
Ответ на possible bug with group by?  (Joseph Shraibman <jks@selectacast.net>)
Ответы Re: possible bug with group by?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
Stephan Szabo wrote:
> 
> > Is this a bug or am I just misunderstanding something?
> >
> > playpen=> create table tablea ( a int,b int , c int );
> > CREATE
> > playpen=> insert into tablea(a, b) values (1 ,2);
> > INSERT 28299 1
> > playpen=> insert into tablea(a, b, c) values (2 ,3, 4);
> > INSERT 28300 1
> > playpen=> select a, b, case when c is null then 'not set' else 'set' end
> > as z from tablea;
> > a|b|z
> > -+-+-------
> > 1|2|not set
> > 2|3|set
> > (2 rows)
> >
> >
> > playpen=> select a, b, case when c is null then 'not set' else 'set' end
> > as z from tablea group by a, b, z;
> > ERROR:  Unable to identify an operator '<' for types 'unknown' and
> > 'unknown'
> >         You will have to retype this query using an explicit cast
> > playpen=>
> 
> I'm not 100% sure, but my guess would be that it's not certain what
> type 'not set' and 'set' are going to be (hence type 'unknown') and when
> it tries to group it, it's unable to determine how to tell what's greater
> than
> something else.

But why would group by need to sort it?  To insert it into a tree to
make lookups of distinct values faster?
> 
> As a workaround, you should be able to do something like the following:
> select a,b, case when c is null then cast('not set' as text) else cast('set'
> as text)
> end as z from tablea group by a, b, z;

That does work. Thanks.


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

Предыдущее
От: Joseph Shraibman
Дата:
Сообщение: Re: possible bug with group by?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: possible bug with group by?