Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZdcYu-0006du-Kg for pgsql-sql@arkaria.postgresql.org; Sun, 20 Sep 2015 11:13:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZdcYt-0005YZ-MB for pgsql-sql@arkaria.postgresql.org; Sun, 20 Sep 2015 11:13:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZdcXv-0004TH-Du for pgsql-sql@postgresql.org; Sun, 20 Sep 2015 11:12:39 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZdcXt-0005WY-1F for pgsql-sql@postgresql.org; Sun, 20 Sep 2015 11:12:38 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id ED49615EE7D5 for ; Sun, 20 Sep 2015 04:07:19 -0700 (PDT) Date: Sun, 20 Sep 2015 04:12:36 -0700 (MST) From: dave To: pgsql-sql@postgresql.org Message-ID: <1442747556700-5866560.post@n5.nabble.com> Subject: Recursive merging of overlapping arrays in a column MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hey mailing list, i have the following Table: I want to merge the arrays which have overlapping elements, so that I get the result which doesn't contain overlapping arrays anymore: I am not an expert in SQL and it took me a long time to come up with this solution: Which gives me the result: Result number 3 is contained in number one and shouldn't be in the output anymore, because I only want non overlapping arrays in the result. Another problem I encountered is that the performance of this query seems to be very bad. I tried running it on a larger table (~400000 arrays) and it is still running after ~10h. I would appreciate any input on this problems, so it would be nice if anyone could give me a hint how to get only the merged arrays without overlaps in the resultset and maybe how to build a more elegant and efficient query. Thanks in advance, Dave -- View this message in context: http://postgresql.nabble.com/Recursive-merging-of-overlapping-arrays-in-a-column-tp5866560.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql