Re: FW: Count & Distinct - Mailing list pgsql-general

From Nils Zonneveld
Subject Re: FW: Count & Distinct
Date
Msg-id 39A90F24.D0CC8ECB@casema.net
Whole thread Raw
In response to FW: Count & Distinct  ("anuj" <Anuj@in-control.de>)
List pgsql-general

anuj wrote:
>
> > >>> select count(distinct(row)) from table;
> hi,
> I have also tried but I am geting an error.
>

It's true that you get an error from trying to execute the query above;
'distinct' is not a function but a keyword, count() is a agregate
function. Following this the correct notation for your query would be:

select count(distinct <row>) from <table>;

I tested this on postgreSQL 7.02 and it works.

I tried this:


NAW=# \d tmpTable
          Table "tmptable"
 Attribute |    Type     | Modifier
-----------+-------------+----------
 id        | integer     |
 name      | varchar(25) |


NAW=# select * from tmpTable;
 id |   name
----+-----------
  1 | Jansen
  2 | Jansen
  3 | Pietersen
  4 | Pietersen
(4 rows)


NAW=# select count(name) from tmpTable;
 count
-------
     4
(1 row)


NAW=# select count(distinct name) from tmpTable;
 count
-------
     2
(1 row)


Success and kind regards,

Nils Zonneveld
--
"Misschien is niets geheel waar, en zelfs dat niet"
Multatuli (Eduard Douwes Dekker) - Idee 1

pgsql-general by date:

Previous
From: Marcin Inkielman
Date:
Subject: Re: table count limitation
Next
From: Miles Thompson
Date:
Subject: Re: table count limitation