Обсуждение: SUM()ming a view's column

Поиск
Список
Период
Сортировка

SUM()ming a view's column

От
Jan Ploski
Дата:
Hello,

I have run into the following problem:

workunit=> select * from v_wutest;
 estimate
----------
     1650
      100
(2 rows)

workunit=> select sum(estimate) from v_wutest;
 sum
------
 4950
  100
(2 rows)



Here, v_wutest is a view which returns two rows. Shouldn't the SUM
aggregate simply add these two values? To me, it looks like a bug.
Isn't it one?

I am using PostgreSQL 7.0.3 here.

-JPL


Re: SUM()ming a view's column

От
Jan Ploski
Дата:
On Wed, Apr 25, 2001 at 04:26:14PM +0200, Jan Ploski wrote:
> Hello,
>
> I have run into the following problem:
>
> workunit=> select * from v_wutest;
>  estimate
> ----------
>      1650
>       100
> (2 rows)
>
> workunit=> select sum(estimate) from v_wutest;
>  sum
> ------
>  4950
>   100
> (2 rows)
>
>
>
> Here, v_wutest is a view which returns two rows. Shouldn't the SUM
> aggregate simply add these two values? To me, it looks like a bug.
> Isn't it one?
>
> I am using PostgreSQL 7.0.3 here.

I just upgraded to 7.1 release 1, and the problem disappeared.
Also, I found a bug in one of my own queries (a missing join
condition), but IMHO it should not have led to the anomaly pictured
above, anyway.

-JPL


Re: SUM()ming a view's column

От
Tom Lane
Дата:
Jan Ploski <jpljpl@gmx.de> writes:
> Here, v_wutest is a view which returns two rows. Shouldn't the SUM
> aggregate simply add these two values? To me, it looks like a bug.

Does the view contain GROUP BY?  If so, yes this is broken in pre-7.1
releases ...

            regards, tom lane

Re: SUM()ming a view's column

От
Jan Ploski
Дата:
On Wed, Apr 25, 2001 at 12:52:15PM -0400, Tom Lane wrote:
> Jan Ploski <jpljpl@gmx.de> writes:
> > Here, v_wutest is a view which returns two rows. Shouldn't the SUM
> > aggregate simply add these two values? To me, it looks like a bug.
>
> Does the view contain GROUP BY?  If so, yes this is broken in pre-7.1
> releases ...

Yes, it does. Everything's clear then :-)
Thanks for your reply (and for the fix in 7.1 to whoever deserves credit!)

-JPL