From: Rudy Gireyev <rgireyev@cnmnetwork.com>
To: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] DISTINCT count(*), possible?
Date: Wed, 16 Jun 1999 13:08:15 -0700
Message-ID: <199906162007.QAA05181@hub.org> (raw)
In-Reply-To: <24839.929543079@sss.pgh.pa.us>
References: <v04020a00b38d1337fb45@[128.40.242.190]>
Out of curiosity, more than anything else.
Would the group by solve this problem?
Rudy
On 16 Jun 99, at 10:24, Tom Lane wrote:
> Another way is
>
> SELECT DISTINCT field INTO temp_table FROM mytable;
> SELECT count(*) FROM temp_table;
> DROP TABLE temp_table;
>
> which is arguably more efficient than the previous solution
> for large tables --- it should involve O(n log n) work rather
> than O(n^2). For a small table, the overhead of creating and
> dropping a table might overshadow the actual work, though.
>
> In 6.5 you can use "INTO TEMP temp_table" and avoid worrying
> about having to invent distinct temp table names for concurrent
> users of the database.
>
> The SQL-standard "SELECT count(DISTINCT field)" would be even nicer,
> of course, but I dunno when someone will get around to it...
>
> regards, tom lane
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: rgireyev@cnmnetwork.com
Subject: Re: [SQL] DISTINCT count(*), possible?
In-Reply-To: <199906162007.QAA05181@hub.org>
References: <v04020a00b38d1337fb45@[128.40.242.190]> <199906162007.QAA05181@hub.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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