From: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Cc: | "Adam Rich" <adam(dot)r(at)sbcglobal(dot)net> |
Subject: | Re: Interval ordering |
Date: | 2012-01-29 22:33:09 |
Message-ID: | 201201291433.09949.adrian.klaver@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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 for postgres?
How about something like:
test(5432)aklaver=>\d timestamp_test
Table "public.timestamp_test"
Column | Type | Modifiers
---------+-----------------------------+-----------
id | integer | not null
txt_fld | text |
ts_fld | timestamp with time zone |
ts_fld2 | timestamp(0) with time zone |
test(5432)aklaver=>SELECT ts_fld2,now()-ts_fld2 from timestamp_test order by
now()-ts_fld2 limit 5;
ts_fld2 | ?column?
------------------------+--------------------------
2011-03-25 14:16:27-07 | 310 days 01:16:04.881631
2011-03-25 14:15:13-07 | 310 days 01:17:18.881631
2010-05-20 13:13:54-07 | 619 days 02:18:37.881631
2010-05-20 12:13:28-07 | 619 days 03:19:03.881631
2010-05-20 10:13:43-07 | 619 days 05:18:48.881631
--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Adam Rich | 2012-01-29 22:39:12 | Re: Interval ordering |
Previous Message | gvim | 2012-01-29 22:27:07 | MS Access easier with PostgreSQL or MySQL? |