pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
count and actual data
2+ messages / 2 participants
[nested] [flat]

* count and actual data
@ 1998-05-04 02:10 Richard Lynch <lynch@lscorp.com>
  1998-05-05 07:10 ` Re: count and actual data Herouth Maoz <herouth@oumail.openu.ac.il>
  0 siblings, 1 reply; 2+ messages in thread

From: lynch@lscorp.com @ 1998-05-04 02:10 UTC (permalink / raw)
  To: pgsql-sql

Okay, it's really something I need to do in Access (don't ask why), but
there's no way I'm going to actually join an Access mailing list.  :-)

select name from users;

gives me:

name
----
Steve
Bill

select count(name) from users;

gives me:

count
-----
 2

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?

--
--
-- "TANSTAAFL" Rich lynch@lscorp.com





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: count and actual data
  1998-05-04 02:10 count and actual data Richard Lynch <lynch@lscorp.com>
@ 1998-05-05 07:10 ` Herouth Maoz <herouth@oumail.openu.ac.il>
  0 siblings, 0 replies; 2+ messages in thread

From: Herouth Maoz @ 1998-05-05 07:10 UTC (permalink / raw)
  To: lynch@lscorp.com; +Cc: 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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1998-05-05 07:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-05-04 02:10 count and actual data Richard Lynch <lynch@lscorp.com>
1998-05-05 07:10 ` Herouth Maoz <herouth@oumail.openu.ac.il>

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