Skip site navigation (1) Skip section navigation (2)

Re: possible bug with group by?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joseph Shraibman <jks(at)selectacast(dot)net>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: possible bug with group by?
Date: 2000-05-24 23:07:47
Message-ID: 13008.959209667@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-sql
Joseph Shraibman <jks(at)selectacast(dot)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

In response to

pgsql-sql by date

Next:From: Stephan SzaboDate: 2000-05-24 23:16:06
Subject: Re: possible bug with group by?
Previous:From: Ryan BradetichDate: 2000-05-24 23:05:58
Subject: Use of index in 7.0 vs 6.5

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group