Thread: Any function for calculating inersect of intervals?

Any function for calculating inersect of intervals?

From
Együd Csaba
Date:
Hi,
wondering if exists any functions which aim to calculate intersect of two
intervals.
E.g. I have four dates (D1, D2, D3, D4) and I want to know if (D1,D2)
intersects (D3,D4) or not.

I konw that it can be done by comparing the dates (>=,<=), but I'm wonder if
I can do it simpler and shorter.

Thank you very much.

-- Csaba

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.


Re: Any function for calculating inersect of intervals?

From
Tom Lane
Date:
=?iso-8859-2?Q?Egy=FCd_Csaba?= <csegyud@vnet.hu> writes:
> E.g. I have four dates (D1, D2, D3, D4) and I want to know if (D1,D2)
> intersects (D3,D4) or not.

See the OVERLAPS operator:
    ( start1, end1 ) OVERLAPS ( start2, end2 )
http://developer.postgresql.org/docs/postgres/functions-datetime.html

            regards, tom lane

Re: Any function for calculating inersect of intervals?

From
Alban Hertroys
Date:
Együd Csaba wrote:
> Hi,
> wondering if exists any functions which aim to calculate intersect of two
> intervals.
> E.g. I have four dates (D1, D2, D3, D4) and I want to know if (D1,D2)
> intersects (D3,D4) or not.

Try INTERSECTS :P

SELECT * FROM table WHERE (D1, D2) INTERSECTS (D3, D4);


Related, are there any operators/functions to test for adjacency (start
of one is end of other), inclusion (interval is inside other interval)
or wrapping (the inverse; interval is around other interval) of intervals?

Alban.


Re: Any function for calculating inersect of intervals?

From
Alban Hertroys
Date:
Alban Hertroys wrote:
> SELECT * FROM table WHERE (D1, D2) INTERSECTS (D3, D4);

Ahem... Let's call that "end of the day dementia" or something... Of
course it's called OVERLAPS, not INTERSECTS...

Re: Any function for calculating inersect of intervals?

From
Együd Csaba
Date:
Thank you Tom.

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Monday, January 17, 2005 5:37 PM
To: Együd Csaba
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Any function for calculating inersect of intervals?

=?iso-8859-2?Q?Egy=FCd_Csaba?= <csegyud@vnet.hu> writes:
> E.g. I have four dates (D1, D2, D3, D4) and I want to know if (D1,D2)
> intersects (D3,D4) or not.

See the OVERLAPS operator:
    ( start1, end1 ) OVERLAPS ( start2, end2 )
http://developer.postgresql.org/docs/postgres/functions-datetime.html

            regards, tom lane


--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.


--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.


Re: Any function for calculating inersect of intervals?

From
Együd Csaba (Freemail)
Date:
Thak you Alban, Tom's solution (OVERLAPS) is the best for me.
bye,
-- Csaba

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Alban Hertroys
Sent: Monday, January 17, 2005 5:49 PM
To: Együd Csaba
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Any function for calculating inersect of intervals?

Együd Csaba wrote:
> Hi,
> wondering if exists any functions which aim to calculate intersect of
> two intervals.
> E.g. I have four dates (D1, D2, D3, D4) and I want to know if (D1,D2)
> intersects (D3,D4) or not.

Try INTERSECTS :P

SELECT * FROM table WHERE (D1, D2) INTERSECTS (D3, D4);


Related, are there any operators/functions to test for adjacency (start of
one is end of other), inclusion (interval is inside other interval) or
wrapping (the inverse; interval is around other interval) of intervals?

Alban.


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.


--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.13 - Release Date: 2005.01.16.