From: | Alban Hertroys <alban(at)magproductions(dot)nl> |
---|---|
To: | Phil Endecott <spam_from_postgresql_general(at)chezphil(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Approximate join on timestamps |
Date: | 2007-03-21 09:51:05 |
Message-ID: | 46010009.6040005@magproductions.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Phil Endecott wrote:
> Dear Experts,
>
> I have two tables containing chronological data, and I want to join them
> using the timestamps. The challenge is that the timestamps only match
> approximately.
>
> My first attempt was something like
>
> t1 join t2 on (abs(t1.t-t2.t)<'1 min'::interval)
>
> Of course there is no "abs" for intervals, and I couldn't think of
> anything better than this
>
> t1 join t2 on (t1.t-t2.t<'1 min'::interval and t2.t-t1.t<'1
> min'::interval)
What about:
t1 join t2
on ((t1.t - interval '30s', t1.t + interval '30s') overlaps (t2.t -
interval '30s', t2.t + interval '30s'))
No need for abs(interval) or repeating conditions that way. My first
attempt was using 'between' instead of 'overlaps', but I don't think
that'll work correctly.
--
Alban Hertroys
alban(at)magproductions(dot)nl
magproductions b.v.
T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede
// Integrate Your World //
From | Date | Subject | |
---|---|---|---|
Next Message | Naz Gassiep | 2007-03-21 10:03:15 | Re: Lifecycle of PostgreSQL releases |
Previous Message | Naz Gassiep | 2007-03-21 09:48:36 | Bulk Data Entry |