Re: Overlapping ranges - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Overlapping ranges
Date
Msg-id 2453A3CB-E597-47B1-875A-3FF4820792EC@gmail.com
Whole thread Raw
In response to Overlapping ranges  (Jason Long <mailing.lists@octgsoftware.com>)
List pgsql-general
On 19 Jun 2014, at 1:47, Jason Long <mailing.lists@octgsoftware.com> wrote:

> I have a large table of access logs to an application.
>
> I want is to find all rows that overlap startdate and enddate with any
> other rows.
>
> The query below seems to work, but does not finish unless I specify a
> single id.
>
> select distinct a1.id
> from t_access a1,
>        t_access a2
> where tstzrange(a1.startdate, a1.enddate) &&
>      tstzrange(a2.startdate, a2.enddate)

You’re comparing overlapping records twice there; you compare all records in a1 to all records in a2. You’ll want to
skipthe records that you already compared. 

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Global value/global variable?
Next
From: M Tarkeshwar Rao
Date:
Subject: Insert query hangs what could be the reason