Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 10618AD7E31 for ; Sun, 17 Jun 2012 13:03:54 -0300 (ADT) Received: from delta01.pnet.xcon.it ([62.48.53.16]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SgHxA-0006TK-VJ for pgsql-hackers@postgresql.org; Sun, 17 Jun 2012 16:03:54 +0000 Received: from localhost (localhost [127.0.0.1]) by delta01.pnet.xcon.it (Postfix) with ESMTP id 7C4B310336D81; Sun, 17 Jun 2012 18:03:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at delta01.pnet.xcon.it Received: from delta01.pnet.xcon.it ([127.0.0.1]) by localhost (delta01.pnet.xcon.it [127.0.0.1]) (amavisd-new, port 10024) with LMTP id s8i0Ct34qrOz; Sun, 17 Jun 2012 18:03:37 +0200 (CEST) Received: from leggeri.gi.lan (188.28.20.174.threembb.co.uk [188.28.20.174]) (Authenticated sender: gianni.ciolli@devise.it) by delta01.pnet.xcon.it (Postfix) with ESMTPSA id 8320810336D80; Sun, 17 Jun 2012 18:03:37 +0200 (CEST) Received: from gianni by leggeri.gi.lan with local (masqmail 0.2.27) id 1SgHwD-7TF-00; Sun, 17 Jun 2012 17:02:53 +0100 Date: Sun, 17 Jun 2012 17:02:53 +0100 From: Gianni Ciolli To: Kevin Grittner Cc: simon@2ndQuadrant.com, misa.simic@gmail.com, gabriele.bartolini@2ndquadrant.it, marco.nenciarini@2ndquadrant.it, pgsql@j-davis.com, pgsql-hackers@postgresql.org Subject: Re: [PATCH] Support for foreign keys with arrays Message-ID: <20120617160253.GA26190@leggeri.gi.lan> References: <4FDDAA39020000250004858F@gw.wicourts.gov> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4FDDAA39020000250004858F@gw.wicourts.gov> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201206/838 X-Sequence-Number: 209678 On Sun, Jun 17, 2012 at 09:58:17AM -0500, Kevin Grittner wrote: > Simon Riggs wrote: > Misa Simic wrote: > > >> IMO, both approaches make sense... > > > > Agreed. > > Can someone provide a practical example of a "foreign key with array" > use case? The only situations I'm able to think of right now are the > same cases where you would now use a table with primary keys of two > tables to provide a many-to-many linkage. Does this proposed feature > handle other cases or handle this type of case better? The way I think about "array foreign keys" is that they represent the "aggregated" form of a classical foreign key. In the aggregated form, each row in the referencing side represents a group of rows in the non-aggregated form. One advantage is that constraints on each group of rows as a whole are now possible, because they become constraints on a single row in the aggregated form. Example. If you have a table of points, then you can have a table of polygons where each polygon contains an array of points. The non-aggregated model would instead require an additional point_polygon table which references both the point and the polygon table, because the point <-> polygon relationship is many-to-many. In the aggregated model, you can easily specify a CHECK constraint that requires each polygon to have at least three points, while the corresponding condition cannot be specified in the non-aggregated model. Cheers, Dr. Gianni Ciolli - 2ndQuadrant Italia PostgreSQL Training, Services and Support gianni.ciolli@2ndquadrant.it | www.2ndquadrant.it