Re: Why DISTINCT ... DESC is slow? - Mailing list pgsql-general

From Richard Huxton
Subject Re: Why DISTINCT ... DESC is slow?
Date
Msg-id 457E7254.1030500@archonet.com
Whole thread Raw
In response to Re: Why DISTINCT ... DESC is slow?  (Anton <anton200@gmail.com>)
List pgsql-general
Anton wrote:
>> SELECT login_id, MAX(collect_time) AS most_recent
>> FROM n_traffic
>> GROUP BY login_id
>> ORDER BY login_id DESC, collect_time DESC
> is not so good:
> =# SELECT login_id, MAX(collect_time) AS most_recent
> -# FROM n_traffic
> -# GROUP BY login_id
> -# ORDER BY login_id DESC, collect_time DESC;
> ERROR:  column "n_traffic.collect_time" must appear in the GROUP BY
> clause or be used in an aggregate function
>
> If I correct this error (add collect time to GROUP BY) I'll just get
> full table, sorted. And I tried to not use aggregate functions because
> they make to do full table scan...

Sorry - my typo. The order-by doesn't need "collect_time" of course.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Anton
Date:
Subject: Re: Why DISTINCT ... DESC is slow?
Next
From: "surabhi.ahuja"
Date:
Subject: any api in libpq to get the number of connections