Re: Interval ordering

Поиск
Список
Период
Сортировка
От Ondrej Ivanič
Тема Re: Interval ordering
Дата
Msg-id CAM6mieJoAkA=zUg5OS1PYsviKtw--DqAE73WXM_E+71Hnhg_6g@mail.gmail.com
обсуждение исходный текст
Ответ на Interval ordering  ("Adam Rich" <adam.r@sbcglobal.net>)
Ответы Re: Interval ordering  ("Adam Rich" <adam.r@sbcglobal.net>)
Список 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 по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Interval ordering
Следующее
От: "Adam Rich"
Дата:
Сообщение: Re: Interval ordering