Re: Counting Distinct Records

From: Thomas F(dot)O'Connell <tfo(at)sitening(dot)com>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: PgSQL - SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Counting Distinct Records
Date: 2004-11-16 23:02:56
Message-ID: A72D6B26-3823-11D9-95C2-000D93AE0944@sitening.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hmm. I was more interested in using COUNT( * ) than DISTINCT *.

I want a count of all rows, but I want to be able to specify which
columns are distinct.

That's definitely an interesting approach, but testing doesn't show it
to be appreciably faster.

If I do a DISTINCT *, postgres will attempt to guarantee that there are
no duplicate values across all columns rather than a subset of columns?
Is that right?

Anyway, I was just wondering if there were any best practices out there
for counting distinct values in sets of values that might not
themselves be distinct.

Thanks for the tips so far!

-tfo

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-260-0005

On Nov 16, 2004, at 4:34 PM, Stephan Szabo wrote:

> On Tue, 16 Nov 2004, Thomas F.O'Connell wrote:
>
>> Is there another way to accomplish what the former is doing, then?
>
> The only thing I can think of is a subselect in from that uses
> distinct.
> select count(*) from (select distinct ...) foo
>
> That also theoretically allows you to use select distinct * inside the
> subselect.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2004-11-17 00:35:50 Re: tree structure photo gallery date quiery
Previous Message Stephan Szabo 2004-11-16 22:34:31 Re: Counting Distinct Records