Re: Counting distinct names - Mailing list pgsql-sql

From Tom Lane
Subject Re: Counting distinct names
Date
Msg-id 17170.956028336@sss.pgh.pa.us
Whole thread Raw
In response to Counting distinct names  ("G. Anthony Reina" <reina@nsi.edu>)
List pgsql-sql
"G. Anthony Reina" <reina@nsi.edu> writes:
> I'd like to find out how many times a unique 'subject_name' is in the
> table. My SQL book says that I should be able to do this:
> select COUNT(DISTINCT subject_name) from table1;
> However, the psql program is giving me an "ERROR:  parser: parse error
> at or near "distinct"".

6.5 doesn't have aggregate(DISTINCT ...).  7.0 does, though.

If you don't want to upgrade right now, you could do something like

SELECT DISTINCT subject_name INTO temp_table FROM table1;
SELECT count(*) FROM temp_table;
DROP TABLE temp_table;
        regards, tom lane


pgsql-sql by date:

Previous
From: "Brett W. McCoy"
Date:
Subject: Re: Counting distinct names
Next
From: Alexander Stetsenko
Date:
Subject: trouble with null