Re: [SQL] DISTINCT & COUNT - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] DISTINCT & COUNT
Date
Msg-id 16209.943640367@sss.pgh.pa.us
Whole thread Raw
In response to Re: [SQL] DISTINCT & COUNT  (Stuart Rison <rison@biochemistry.ucl.ac.uk>)
List pgsql-sql
Stuart Rison <rison@biochemistry.ucl.ac.uk> writes:
> You can however do:

> SELECT DISTINCT c.cid
> FROM a,b,c
> WHERE a.aid=b.aid
> AND a.somefield=1 and a.otherfield=2
> AND c.cid=a.cid;

> and if your are using a interface (e.g. DBI::DBD::Pg) then you can get
> the number of tuples returned...

Or do the SELECT into a temp table, followed by fetching count(*) on the
temp table.  Ugly, but avoids transferring what might be a lot of rows
to the frontend.

DISTINCT within aggregate functions is on the TODO list, but I don't
know when it will happen.
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [SQL] 6.5.3 - backend closes if wrong parameters to NULLIF, CASE
Next
From: "Zodiac Speaker"
Date:
Subject: TEST MESSAGE - PLEASE IGNORE