From: Mark Volpe <volpe.mark@epamail.epa.gov>
To: pgsql-sql@postgresql.org
Subject: Aggregates and Views
Date: Fri, 14 Jan 2000 16:16:44 -0500
Message-ID: <387F923C.3E279281@epamail.epa.gov> (raw)
Is it possible to use an aggregate on a view
that contains an aggregate? I can't seem to get
this to work:
(cut & paste into psql to reproduce)
CREATE TABLE x ( n int );
INSERT INTO x VALUES(5);
INSERT INTO x VALUES(5);
INSERT INTO x VALUES(5);
INSERT INTO x VALUES(10);
INSERT INTO x VALUES(10);
INSERT INTO x VALUES(10);
INSERT INTO x VALUES(15);
INSERT INTO x VALUES(15);
INSERT INTO x VALUES(15);
INSERT INTO x VALUES(15);
INSERT INTO x VALUES(20);
INSERT INTO x VALUES(20);
SELECT count(*) from x; -- Correctly returns 12
CREATE VIEW y AS SELECT n, count(*) AS total FROM x GROUP BY n;
SELECT * FROM y; -- Correctly returns (5,3), (10,3), (15,4),
(20,2)
-- So far so good
-- but if I do this:
SELECT count(*) FROM y; -- Instead of getting 4, I get 3,3,4,2
SELECT sum(total) FROM y; -- Returns nonsense values 0, 9, 12, 8
DROP TABLE x;
DROP VIEW y;
(end cut & paste)
Thanks,
Mark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: volpe.mark@epamail.epa.gov
Subject: Re: Aggregates and Views
In-Reply-To: <387F923C.3E279281@epamail.epa.gov>
References: <387F923C.3E279281@epamail.epa.gov>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox