Re: Absolute value of intervals

From: Scott Bailey <artacus(at)comcast(dot)net>
To:
Cc: PostgreSQL - General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Absolute value of intervals
Date: 2009-10-27 15:49:38
Message-ID: 4AE71692.3080707@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joshua Berry wrote:
> I couldn't find the operator '@' for intervals and found this thread
> from over six years ago:
> http://archives.postgresql.org/pgsql-general/2003-09/msg00292.php
>
> | "Claudio Lapidus" <clapidus(at)hotmail(dot)com> writes:
> | > Bruce Momjian wrote:
> | >> Why would you want an abolute value of a negative interval?
> |
> | > Because I'm trying to match pairs of records that satisfy certain criteria,
> |
> | Given that we have a unary-minus operator for intervals, I see no
> | conceptual objection to having an absolute-value operator (and \do shows
> | that interval is the only standard datatype that has the former but not
> | the latter).
> |
> | However, given that it doesn't seem to be a really widely useful
> | operator, I think this is the kind of itch that you'll have to scratch
> | yourself. Send us a patch and it'll get into the next release ...
> |
> | regards, tom lane
>
> Is this is the case now? I have some data that is related but requires
> fuzzy joining on timestamps within a time interval.
>
> I'd like to be able to do this:
> select * from enviados e, recibidos r where @ (e.fecha - r.fecha) <
> interval '1 second'
>
> rather than this:
> select * from enviados e, recibidos r where (e.fecha - r.fecha) <
> interval '1 second' AND (r.fecha - e.fecha) < interval '1 second'
>
> or this:
> select * from enviados e, recibidos r where (r.fecha + interval '1
> seconds', r.fecha - interval '1 seconds') OVERLAPS (e.fecha, e.fecha);
>
> If such an operator doesn't exist yet, I'm keen to try to generate a
> patch and tests; but I could use some pointers as to which project
> files that should be related to such a change.
>
> Regards,
> -Joshua Berry
>

You should test for a positive or negative interval against INTERVAL '0
seconds' because you can have a positive interval that is a fraction of
a second.

But we've got two projects that implement a period data type, pgTemporal
and Chronos.
http://pgfoundry.org/projects/temporal/
http://pgfoundry.org/projects/timespan/

Scott Bailey

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2009-10-27 16:35:04 Re: Upgrade from 8.2 to 8.3 & catching errors in functions
Previous Message Sam Mason 2009-10-27 15:29:42 Re: Absolute value of intervals