Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it?

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Aaron Holtz <aholtz(at)bright(dot)net>, pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Any ideas why this doesn't work or how to rewrite it?
Date: 1999-04-29 14:44:41
Message-ID: l03130307b34e1da86145@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

At 18:50 +0300 on 28/04/1999, Aaron Holtz wrote:

> db=> select count(distinct customer_username) from customerdata;
> ERROR: parser: parse error at or near "distinct"
>
> How do you get a count of distinct data output via postgres? I can always
> just count the number of tuples returned but this seemed to be a valid
> query.

Valid it is, but not yet supported in PostgreSQL.

An (ugly) workaround would be something along the lines of:

SELECT count(customer_username)
FROM customerdata c1
WHERE int( oid ) = (
SELECT min( int( c2.oid ) )
FROM customerdata c2
WHERE c1.customer_username = c2.customer_username
);

The WHERE clause causes only rows whose OIDs are the minimal for the
current username to be selected. Thus only one row is selected for each
username. And this is countable.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim Mercer 1999-04-29 14:51:07 serious bug in "alter table tbname rename to newname"
Previous Message Margarita Barvinok 1999-04-29 14:36:11 Re: [GENERAL] LIMIT QUESTION