Re: Interval ordering

From: "Adam Rich" <adam(dot)r(at)sbcglobal(dot)net>
To: 'Ondrej Ivanič' <ondrej(dot)ivanic(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Interval ordering
Date: 2012-01-30 00:37:29
Message-ID: 006a01ccdee7$591aec10$0b50c430$@sbcglobal.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

>> SELECT ts_fld2,abs(extract(epoch from '2011-03-25
>> 14:15:25-07'::timestamptz)-extract(epoch from ts_fld2)) from timestamp_test order
>> by abs(extract(epoch from '2011-03-25 14:15:25-07'::timestamptz)-extract(epoch
>> from ts_fld2)) limit 5;

Thanks to Ondrej and Adrian, who both provided working solutions using extract/epoch.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-01-30 01:02:28 Re: Question about (probably wrong) index scan cost for conditional indexes
Previous Message Peter Geoghegan 2012-01-29 23:17:20 Re: FOSDEM booth volunteer