Re: Counting unique rows as an aggregate.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: r_musta <zepolen(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Counting unique rows as an aggregate.
Date: 2008-09-29 23:36:36
Message-ID: 26009.1222731396@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

r_musta <zepolen(at)gmail(dot)com> writes:
> However, this is starting to become too slow (as there are about 10 of
> these queries), and therefore I need to write an aggregate function
> which lets me do:

> SELECT count_unique(make), count_unique(color) from table WHERE >criteria<;

I must be missing something, because I don't see why you couldn't do

SELECT count(distinct make), count(distinct color) from table WHERE >criteria<;

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Diehl 2008-09-30 00:02:10 Re: Can't cast from char to integer...
Previous Message Tom Lane 2008-09-29 23:31:32 Re: database question