Re: absolute value fro timestamps

From: "Claudio Lapidus" <clapidus(at)hotmail(dot)com>
To: "Bruce Momjian" <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: absolute value fro timestamps
Date: 2003-08-29 21:44:07
Message-ID: BAY7-DAV34vJj3LsGlo000062c7@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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,
one of which is that both records have a timestamp that *may* be slightly
offset between them, so I substract the two and the result must be no
greater than the allowed offset. I don't know which record has the greater
timestamp, so I don't know the sign of the substraction in advance.

>
> This works:
>
> test=> select -(interval '-1');
> ?column?
> ----------
> 01:00:00
> (1 row)
>
> so I suppose you could create a function or CASE statement to get the
> absolute value.
>

In the meantime I implemented it the following way:

\set maxoffset 4
select
...
where
abs(extract(epoch from age(m1.ts, m2.ts))) < :maxoffset
...

Which I think is more compact. Anyway, it would be nice to be able to write
directly

abs(age(m1.ts, m2.ts))

IMHO.

thanks
cl.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Brian J. Erickson 2003-08-29 21:55:28 Postgresql ODBC Question
Previous Message Carmen Gloria Sepulveda Dedes 2003-08-29 21:42:08 Re: A question about postgresql