Re: Ordering with GROUPs

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Julian Scarfe" <julian(dot)scarfe(at)ntlworld(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Ordering with GROUPs
Date: 2002-08-18 19:55:38
Message-ID: 1115.1029700538@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Julian Scarfe" <julian(dot)scarfe(at)ntlworld(dot)com> writes:
> SELECT location.ident, node, count(*) from location, message
> WHERE location.ident = message.ident
> GROUP BY location.ident;
> ERROR: Attribute location.node must be GROUPed or used in an aggregate
> function

> it obviously fails. If node were an integer I could just use an aggregate
> like max() or similar, but it's not, and there's no suitable aggregate for
> point. I can create a trivial one as a work around, but I hope I don't have
> to.

ISTM the problem here is the lack of any ordering operator for POINT,
which defeats GROUP BY, *plus* the lack of any aggregate you might use
for an aggregate-based solution. This is not really a language failing
but a problem with an impoverished datatype. So, if you don't like
Bruno's subselect-based workaround, the dummy aggregate seems the way
to go.

SQL99 contains a whole bunch of verbiage whose intent seems to be that
if you GROUP BY a unique or primary-key column, you can reference the
other columns of that table without aggregation (essentially, the
system treats them as implicitly GROUP BY'd). Sooner or later we'll
probably get around to implementing that, and that would solve your
problem as long as you declare location.ident properly.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andre Schubert 2002-08-19 05:31:42 Re: Need Help for select
Previous Message Tom Lane 2002-08-18 18:25:08 Re: Unexplained SQL behavior