counting rows of grouped query (problem with views)

From: Nabil Sayegh <nsmail(at)sayegh(dot)de>
To: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: counting rows of grouped query (problem with views)
Date: 2001-03-09 18:08:12
Message-ID: 20010309180010.6F2CE3EDA@plserver.of.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi all,

(short)
is there any possibility to count the number of rows resulting from a
grouped query (from a view containing a grouped query) ?

(long)
CREATE TABLE tmp (a int, b int, c text);
INSERT INTO tmp values (1, 1, 'a');
INSERT INTO tmp values (2, 1, 'b');
INSERT INTO tmp values (1, 2, 'c');
INSERT INTO tmp values (2, 2, 'd');

CREATE view damn as select a, b from tmp group by a, b;

I have no rights to access tmp directly, I have to use the view !!!

praxis=# select * from damn where b=2;
a | b
---+---
1 | 2
2 | 2
(2 rows)

okay, this is what I want.

praxis=# select count(*) from damn where b=2;
count
-------
1
1
(2 rows)

I dont want the aggregate function to be used on each group, I want it
to count all the rows.
IMHO the view should act as a table (and therefor should UNGROUP the
result)

P.S.: I use 7.0.3
P.P.S.: How stable is 7.1

TIA
cu
--

Nabil Sayegh
GPG-Key available at http://www.sayegh.de
(see http://www.gnupg.org for details)

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Charles Welch 2001-03-09 19:17:46 Number of Records in a Table
Previous Message Nabil Sayegh 2001-03-09 17:56:18 counting rows of grouped query (problem with views)