adding "order by" to a "group by" query - Mailing list pgsql-sql

From Louis-David Mitterrand
Subject adding "order by" to a "group by" query
Date
Msg-id 20081206171037.GA11617@apartia.fr
Whole thread Raw
Responses Re: adding "order by" to a "group by" query
List pgsql-sql
Hi,

This query:
select p.id_person, person_name(p), array_accum(distinct pt.type_fr)    from person p    left join person_to_event x
using(id_person)    left join person_type pt using (id_person_type)    where person_name(p) ilike '%will%'     group by
p.id_person,person_name(p);

returns:
id_person |     person_name      |          array_accum          
-----------+----------------------+-------------------------------      181 | William Eggleston    | {comédien}
200| William H.Macy       | {comédien}      242 | William Nicholson    | {auteur}      309 | William Friedkin     |
{réalisateur}     439 | William Shakespeare  | {auteur}      591 | William Christie     | {musicien}      786 | Paul
AndrewWilliams | {réalisateur}     1015 | William Mesguich     | {comédien,"metteur en scène"}
 

But if I append this
 order by pt.type_fr = 'comédien';

I get this error:
ERROR:  column "pt.type_fr" must appear in the GROUP BY clause or be used in an aggregate function

It seems I am using pt.type_fr in an aggregate function (array_accum()),
yet I get the error.

Is there a way to to have a certain pt.type_fr bubble up (or down) in my
search?

Thanks,

-- 
http://www.critikart.net


pgsql-sql by date:

Previous
From: "Oliveiros Cristina"
Date:
Subject: Re: Best way to "and" from a one-to-many joined table?
Next
From: Andreas Kretschmer
Date:
Subject: Re: adding "order by" to a "group by" query