Re: count and actual data

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: lynch(at)lscorp(dot)com (Richard Lynch)
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: count and actual data
Date: 1998-05-05 07:10:03
Message-ID: l03110700b1746951e12c@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 5:10 +0300 on 4/5/98, Richard Lynch wrote:

> Now, I really want the result from the first query, *AND* the count from
> the second query.
>
> select name, count(name) from users;
>
> would be fine, even if it did give me the count too many times, but it
> won't work.
>
> So. how does one get both the data and the count as results in table format
> from a query?

Define a function, and select both it and the data...

CREATE FUNCTION cnt_usr() RETURNS int4
AS 'SELECT COUNT(name) FROM users'
LANGUAGE 'sql';

SELECT name, cnt_usr()
FROM users;

You do realize, however, that it will do the counting over and over for
each line?

Herouth

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Oliver Mueschke 1998-05-11 21:43:40 subscribe
Previous Message Roland B. Roberts 1998-05-05 00:18:03 subscribe