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

From Jorge Godoy
Subject Re: Why overlaps is not working
Date
Msg-id 8764dos5sy.fsf@gmail.com
Whole thread Raw
In response to Re: Why overlaps is not working  ("Andrus" <eetasoft@online.ee>)
List pgsql-general
"Andrus" <eetasoft@online.ee> writes:

> Jorge,
>
> Thank you very much. Now I try to William Leite Araújo solution by replacing
>
> WHERE (a,b) OVERLAPS (c,d)
>
> with
>
> WHERE  ( c BETWEEN a AND b ) OR  ( d BETWEEN a AND b )
>
> Is this OK ?

From bare tests this looks OK.

> This requires writing a and b expressions twice. How to avoid repeating
> expressions ?

You can use a function for that and use variables for the four arguments:

CREATE OR REPLACE FUNCTION f_v_same_day_overlaps(date,
       date, date, date, out overlaps bool) as
$_$
SELECT (($3 between $1 and $2) or ($4 between $1 and $2));
$_$ language sql;


Be seeing you,
--
Jorge Godoy      <jgodoy@gmail.com>

pgsql-general by date:

Previous
From: Craig White
Date:
Subject: Re: authentication question
Next
From: Alvaro Herrera
Date:
Subject: Re: autovacuum blues