Re: group by not returning sorted rows

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Bret Hughes <bhughes(at)elevating(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: group by not returning sorted rows
Date: 2004-04-05 22:54:00
Message-ID: 20040405154818.F18308@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 5 Apr 2004, Bret Hughes wrote:

> select cities.name as city, buildings.name as building,
> pagename,
> log_date ,
> sum(exhibition_count) as tot
> from logrecords
> join cities on (logrecords.city=cities.num)
> join buildings on (logrecords.building=buildings.num)
> where advertiser = 'Nielsens' and
> log_date >= '01/01/2004' and
> log_date <= '01/31/2004'
> group by cities.name, buildings.name,pagename,log_date ;
>
> I have migrated a database from a redhat 7.3 box running
> [bhughes(at)compaq3 reports]$ rpm -q postgresql
> postgresql-7.2.3-5.73
>
> To a redhat 9 box running :
> [bhughes(at)compaq2 reports]$ rpm -q postgresql
> postgresql-7.4.2-1PGDG
>
> and the rows resulting from the query are no longer sorted by log date.
> Is this a change since 7.2x?

Yes.

> I can achieve the results I need by adding an order by clause identical
> to the group by but this seems counter intuitive since the rows have to
> be ordered anyway.

They no longer need to always be pre-ordered in order to do the group by
(this depends on plan).

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message scott.marlowe 2004-04-05 22:55:45 Re: DB question - Merging data from one table to another.
Previous Message Jeff Eckermann 2004-04-05 22:34:42 Re: Question on pgsql trigger