Re: [SQL] SQL query problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: vikrant(at)chemquick(dot)com
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] SQL query problem
Date: 2000-02-28 07:38:03
Message-ID: 21249.951723483@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Vikrant Rathore" <vikrant(at)chemquick(dot)com> writes:
> I have been able to run the following query successfully on postgresl-
> 6.3.2 but unable to run the same in Postgresql-6.5.2.

> select
> a.offer_id,a.comp_id,prod_name,date(offer_date),time(offer_date),
> ...
> group by a.offer_id
> ...

If you group by a.offer_id, then your select list can't refer to
any other columns except as aggregate-function arguments. For
example, it would make sense to ask for min(a.comp_id) to get the
smallest comp_id out of each group of rows with the same offer_id.
But that group of rows doesn't necessarily all have the same comp_id,
so you can't expect to ask for unvarnished comp_id and get a well-
defined answer.

Before about v6.5, Postgres was fairly lax about checking for this
logical error (which is also a violation of the SQL standard), and
would in fact give you back some randomly-chosen comp_id value.
Recent versions detect the error, however.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2000-02-28 07:50:01 Re: [SQL] prob with aggregate and group by - returns multiples
Previous Message George Dau 2000-02-28 06:22:46 prob with aggregate and group by - returns multiples