Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMjgZ-00077y-VW for pgsql-hackers@arkaria.postgresql.org; Sat, 04 May 2019 01:41:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hMjgX-0007ng-91 for pgsql-hackers@arkaria.postgresql.org; Sat, 04 May 2019 01:41:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMjgW-0007jY-Us for pgsql-hackers@lists.postgresql.org; Sat, 04 May 2019 01:41:52 +0000 Received: from xvm-110-146.dc2.ghst.net ([46.226.110.146] helo=fetter.org) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hMjgT-0003bq-VE for pgsql-hackers@postgresql.org; Sat, 04 May 2019 01:41:52 +0000 Received: by fetter.org (Postfix, from userid 1001) id 456B942BBC; Sat, 4 May 2019 03:41:48 +0200 (CEST) Date: Sat, 4 May 2019 03:41:47 +0200 From: David Fetter To: Paul Jungwirth Cc: Pgsql Hackers Subject: Re: range_agg Message-ID: <20190504014147.GC28936@fetter.org> References: <16d71dc8-34cf-5ebd-1ce5-ccd93c0a14f9@illuminatedcomputing.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16d71dc8-34cf-5ebd-1ce5-ccd93c0a14f9@illuminatedcomputing.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, May 03, 2019 at 03:56:41PM -0700, Paul Jungwirth wrote: > Hello, > > I wrote an extension to add a range_agg function with similar behavior to > existing *_agg functions, and I'm wondering if folks would like to have it > in core? Here is the repo: https://github.com/pjungwir/range_agg > > I'm also working on a patch for temporal foreign keys, and having range_agg > would make the FK check easier and faster, which is why I'd like to get it > added. But also it just seems useful, like array_agg, json_agg, etc. > > One question is how to aggregate ranges that would leave gaps and/or > overlaps. This suggests two different ways to extend ranges over aggregation: one which is a union of (in general) disjoint intervals, two others are a union of intervals, each of which has a weight. Please pardon the ASCII art. The aggregation of: [1, 4) [2, 5) [8, 10) could turn into: {[1,5), [8, 10)} (union without weight) {{[1,2),1}, {[2,4),2}, {[4,5),1}, {[8,10),1}} (strictly positive weights which don't (in general) cover the space) {{[1,2),1}, {[2,4),2}, {[4,5),1}, {[5,8),0}, {[8,10),1}} (non-negative weights which guarantee the space is covered) There is no principled reason to choose one over the others. > What do people think? I plan to work on a patch regardless, so that I can > use it for temporal FKs, but I'd appreciate some feedback on the "user > interface". I think the cases above, or at least the first two of them, should be available. They could be called range_agg, weighted_range_agg, and covering_range_agg. Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate