SUM()ming a view's column

Started by Jan Ploskialmost 25 years ago4 messagesgeneral
Jump to latest
#1Jan Ploski
jpljpl@gmx.de

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

#2Jan Ploski
jpljpl@gmx.de
In reply to: Jan Ploski (#1)
Re: SUM()ming a view's column

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

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jan Ploski (#1)
Re: SUM()ming a view's column

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

#4Jan Ploski
jpljpl@gmx.de
In reply to: Tom Lane (#3)
Re: SUM()ming a view's column

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