Re: Interval ordering - Mailing list pgsql-general

From Ondrej Ivanič
Subject Re: Interval ordering
Date
Msg-id CAM6mieJoAkA=zUg5OS1PYsviKtw--DqAE73WXM_E+71Hnhg_6g@mail.gmail.com
Whole thread Raw
In response to Interval ordering  ("Adam Rich" <adam.r@sbcglobal.net>)
Responses Re: Interval ordering  ("Adam Rich" <adam.r@sbcglobal.net>)
List pgsql-general
Hi,

On 30 January 2012 09:19, Adam Rich <adam.r@sbcglobal.net> 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@gmail.com)

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Interval ordering
Next
From: "Adam Rich"
Date:
Subject: Re: Interval ordering