Re: possible bug with group by? - Mailing list pgsql-sql

From Tom Lane
Subject Re: possible bug with group by?
Date
Msg-id 13008.959209667@sss.pgh.pa.us
Whole thread Raw
In response to possible bug with group by?  (Joseph Shraibman <jks@selectacast.net>)
List pgsql-sql
Joseph Shraibman <jks@selectacast.net> writes:
> 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

It's not GROUP BY's fault, it's just the oft-repeated issue about
quoted string literals not having any definite type in Postgres.
The parser postpones assigning a type until it sees the literal used
in a context where a type can be determined --- and in a case like
this, it never can.  You need to force the issue with a cast, eg

select a, b,    case when c is null then 'not set'::text else 'set'::text end as z
from tablea group by a, b, z;
        regards, tom lane


pgsql-sql by date:

Previous
From: "Stephan Szabo"
Date:
Subject: Re: possible bug with group by?
Next
From: Joseph Shraibman
Date:
Subject: Re: possible bug with group by?