Re: Absolute value of intervals - Mailing list pgsql-general

From Jasen Betts
Subject Re: Absolute value of intervals
Date
Msg-id hdr2if$7af$1@reversiblemaps.ath.cx
Whole thread Raw
In response to Absolute value of intervals  (Joshua Berry <yoberi@gmail.com>)
List pgsql-general
On 2009-11-07, Joshua Berry <yoberi@gmail.com> wrote:
> On Mon, Nov 2, 2009 at 8:35 AM, Jasen Betts <jasen@xnet.co.nz> wrote:
>|
>| for this case: convert to seconds and then do abs.
>|
>|  select * from enviados e, recibidos r where abs(extract ( epoch from
>|  (e.fecha - r.fecha) )) < 1
>
> Cheers for that. The query cost is pretty heavy, but the same as the
> following query which involves two WHERE sections:

indeed, this one should be more efficient but is not exactly identical.

select * from enviados e, recibidos r where e.fecha between  r.fecha
-'1s' and r.fecha +'1s';

the difference being that the above includes the case where the
difference is exactly 1 second.

this might work better:

select * from enviados e, recibidos r where e.fecha between  r.fecha
-'0.999999s' and r.fecha +'0.999999s';

it depends how critical the edge cases are.


pgsql-general by date:

Previous
From: Malm Paul
Date:
Subject: dumping parts of a database
Next
From: Jasen Betts
Date:
Subject: Re: Backups