Search Postgresql Archives

Re: Interval ordering

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 30 January 2012 09:19, Adam Rich <adam.r@xxxxxxxxxxxxx> wrote:
> desired time, I want to show them the 5 times from the table that are
> closest to their
>
> input.  I expected to do this using abs() like such:
>
> select mytime from mytable order by abs(usertime-mytime) asc limit 5;
>
> However, the difference between times is an interval, and there appears to
> be no
>
> absolute value operator for those.  My next thought was to convert the
> interval

try this:
select mytime from mytable order by abs(extract(epoch from
(usertime-mytime))) asc limit 5;

-- 
Ondrej Ivanic
(ondrej.ivanic@xxxxxxxxx)

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux