Re: Why overlaps is not working - Mailing list pgsql-general

From Ian Harding
Subject Re: Why overlaps is not working
Date
Msg-id 725602300611130743v1bd4c477kb25602673f658453@mail.gmail.com
Whole thread Raw
In response to Re: Why overlaps is not working  ("Andrus" <eetasoft@online.ee>)
List pgsql-general
>
> If first period end and second period start dates are the same, I need that in this case expression
> returns true.
> Is it possible to implement this using OVERLAPS operator ?
>

I think the best workaround is a function of some kind in whichever
language you choose.  I think you could actually clobber overlaps()
but I chose to give mine a different name.  In my world, all date
ranges have a start, but can have an indefinite end (null).

CREATE OR REPLACE FUNCTION "isoverlap" (date,date,date,date) RETURNS
boolean LANGUAGE pltcl  AS '

set d1 [clock scan $1]
set d3 [clock scan $3]

if {[string length $2] == 0} {
    set d2 0
} else {
    set d2 [clock scan $2]
}
if {[string length $4] == 0} {
    set d4 0
} else {
    set d4 [clock scan $4]
}

if {($d2 >= $d3 && ($d1 <= $d4 || !$d4)) ||
    ($d1 <= $d4 && ($d2 >= $d3 || !$d2)) ||
    (!$d2 && !$d4)} {

    return true
} else {
    return false
}

' ;

pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: Inserting data in composite types
Next
From: Scott Marlowe
Date:
Subject: Re: Speed of postgres compared to ms sql, is this