Re: Interval ordering

From: Ondrej Ivanič <ondrej(dot)ivanic(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Interval ordering
Date: 2012-01-29 22:49:58
Message-ID: CAM6mieJoAkA=zUg5OS1PYsviKtw--DqAE73WXM_E+71Hnhg_6g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

On 30 January 2012 09:19, Adam Rich <adam(dot)r(at)sbcglobal(dot)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(dot)ivanic(at)gmail(dot)com)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gavin Flower 2012-01-29 23:16:12 Re: MS Access easier with PostgreSQL or MySQL?
Previous Message Adrian Klaver 2012-01-29 22:48:22 Re: Interval ordering