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

Re: adding "order by" to a "group by" query

From: John Lister <john(dot)lister-ps(at)kickstone(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: adding "order by" to a "group by" query
Date: 2008-12-06 18:24:25
Message-ID: 493AC359.6060709@kickstone.com (view raw or flat)
Thread:
Lists: pgsql-sql
 >(still curious about the "must be used in an aggregate function" error
 >though... because I do use it in an aggregate)


You're original query grouped on the person id and name, therefore you 
can only return (and order by) these functions or the result of an 
aggregate function on other columns (such as the array_accum function).

I'm no expert, but I think the error is slightly misleading, normally 
you would order by the result of an aggregate function but maybe the 
parser does this implicitly for you sometimes. does

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)
        order by 3;


work for you?


In response to

Responses

pgsql-sql by date

Next:From: Louis-David MitterrandDate: 2008-12-06 18:36:20
Subject: Re: adding "order by" to a "group by" query
Previous:From: Andreas KretschmerDate: 2008-12-06 18:23:25
Subject: Re: adding "order by" to a "group by" query

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