Re: absolute value fro timestamps - Mailing list pgsql-general

From Claudio Lapidus
Subject Re: absolute value fro timestamps
Date
Msg-id BAY7-DAV34vJj3LsGlo000062c7@hotmail.com
Whole thread Raw
In response to absolute value fro timestamps  ("Claudio Lapidus" <clapidus@hotmail.com>)
Responses Re: absolute value fro timestamps  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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.


pgsql-general by date:

Previous
From: Josué Maldonado
Date:
Subject: Re: TCL trigger doesn't work after deleting a column
Next
From: Bruce Momjian
Date:
Subject: Re: absolute value fro timestamps