pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stuart Rison <stuart@ludwig.ucl.ac.uk>
To: pgsql-sql@postgresql.org
Subject: DISTINCT within aggregates.
Date: Wed, 10 Mar 1999 17:01:15 +0000
Message-ID: <v04003a06b30c53de10b9@[128.40.242.190]> (raw)

Hi,

I have PG 6.4 which does not appear to support DISTINCT with aggregates.

Here's an example with the following table:

key|numero
---+-----
  1|one
  2|two
  3|three
  4|one
  4|four
  2|one
(6 rows)

brecard10=> select count(numero) from test;
count
-----
    6
(1 row)

brecard10=>  select count(numero) from test group by value;
count
-----
    1
    3
    1
    1
(4 rows)

brecard10=> select count(distinct numero) from test group by value;
ERROR:  parser: Syntax error at or near "distinct"

I want to be able to count how many DISTINCT 'numero' entries there are in
test (i.e 4).
The first statement is a simple count.
The second uses a group which does indeed tell us that there are four
different 'numero's but does not return a unique count.
The last statement is the statement to use (at least according to my SQL
handbook - Bowman et al.) but is not supported by PG 6.4.

Has anybody found a workaround?

cheers,

Stuart.


+-------------------------+--------------------------------------+
| Stuart Rison            | Ludwig Institute for Cancer Research |
+-------------------------+ 91 Riding House Street               |
| Tel. (0171) 878 4041    | London, W1P 8BT, UNITED KINGDOM.     |
| Fax. (0171) 878 4040    | stuart@ludwig.ucl.ac.uk              |
+-------------------------+--------------------------------------+





Message-ID: <v04003a06b30c53de10b9@[128.40.242.190]>
Permalink:  ../v04003a06b30c53de10b9@%5B128.40.242.190%5D/
Also on:    postgresql.org/message-id/v04003a06b30c53de10b9@[128.40.242.190]

 · 

reply

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: stuart@ludwig.ucl.ac.uk
  Subject: Re: DISTINCT within aggregates.
  In-Reply-To: <v04003a06b30c53de10b9@[128.40.242.190]>
  References: <v04003a06b30c53de10b9@[128.40.242.190]>

* 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