Re: count function alternative in postgres

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "junaidmalik14" <junaidmalik14(at)gmail(dot)com>, "Robert Haas" <robertmhaas(at)gmail(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count function alternative in postgres
Date: 2010-04-05 16:29:52
Message-ID: 4BB9C9B00200002500030463@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> You can do:
>
> SELECT COUNT(*) FROM (SELECT DISTINCT profile.id, profile.name,
> profile.age FROM ...) x;

Ah, I see what they wanted now. In older versions of PostgreSQL,
they might get better performance in some cases by using GROUP BY:

SELECT COUNT(*) FROM
(SELECT id, name, age FROM profile GROUP BY id, name, age) x;

I don't remember offhand what version started considering a hash for
DISTINCT.

-Kevin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2010-04-05 17:01:10 Re: count function alternative in postgres
Previous Message Greg Sabino Mullane 2010-04-05 16:29:49 Show schema name on REINDEX DATABASE