Re: Getting the amount of overlap when using OVERLAPS

From: vishal saberwal <vishalsaberwal(at)gmail(dot)com>
To: Tony Wasson <ajwasson(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Getting the amount of overlap when using OVERLAPS
Date: 2005-09-23 00:28:58
Message-ID: 3e74dc2505092217284a240c1d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

create or replace function test1() returns text as $$
DECLARE
mm varchar;
ma bool;
BEGIN
SELECT into ma (DATE '2001-02-16', DATE '2001-12-21') OVERLAPS (DATE
'2001-10-30', DATE '2002-10-30');
if (ma) then
select into mm (age(DATE '2001-02-16', DATE '2001-12-21')-age(DATE
'2001-10-30', DATE '2002-10-30'));
end if;
return mm;
END;
$$ language plpgsql strict;
select * from test1();

vish

On 9/22/05, Tony Wasson <ajwasson(at)gmail(dot)com> wrote:
>
> Given 2 date ranges, the overlaps functions returns TRUE or FALSE. I
> want to find the # of days that are overlapping. Is there a "built in"
> way to do this? Should I just write a function to do it?
>
> For instance, this example overlaps, but I want to know how much does
> it overlap?
>
> SELECT (DATE '2001-02-16', DATE '2001-12-21') OVERLAPS
> (DATE '2001-10-30', DATE '2002-10-30');
>
> Thanks in advance!
> Tony Wasson
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2005-09-23 02:24:02 Re: PQtrace doesn't work
Previous Message CSN 2005-09-22 23:35:54 Re: Finding (and deleting) dupes in relation table