Re: [GENERAL] Interval ordering

2012-01-29 Thread Adam Rich
>> 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 >

Re: [GENERAL] Interval ordering

2012-01-29 Thread Ondrej Ivanič
Hi, On 30 January 2012 09:19, Adam Rich 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

Re: [GENERAL] Interval ordering

2012-01-29 Thread Adrian Klaver
On Sunday, January 29, 2012 2:39:12 pm Adam Rich wrote: > > How about something like: > > test(5432)aklaver=>SELECT ts_fld2,now()-ts_fld2 from timestamp_test order > > by > > > now()-ts_fld2 limit 5; > > Thanks Adrian, > Let me explain the problem better. Say my table has 24 entries, one for >

Re: [GENERAL] Interval ordering

2012-01-29 Thread Adam Rich
> How about something like: > test(5432)aklaver=>SELECT ts_fld2,now()-ts_fld2 from timestamp_test order by > now()-ts_fld2 limit 5; Thanks Adrian, Let me explain the problem better. Say my table has 24 entries, one for each hour, midnight through 11 pm. If the user enters "6:30 PM", I want to

Re: [GENERAL] Interval ordering

2012-01-29 Thread Adrian Klaver
On Sunday, January 29, 2012 2:19:38 pm Adam Rich wrote: > Hello, > > I have a table with a list of times. When the user provides my application > with a > > desired time, I want to show them the 5 times from the table that are > closest to their > > > > Is this ugly query really necessary fo

[GENERAL] Interval ordering

2012-01-29 Thread Adam Rich
Hello, I have a table with a list of times. When the user provides my application with a 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 l