Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 3A97AAD7E2E for ; Sun, 17 Jun 2012 03:54:50 -0300 (ADT) Received: from mail-pb0-f46.google.com ([209.85.160.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Sg9Nn-0006mG-V5 for pgsql-hackers@postgresql.org; Sun, 17 Jun 2012 06:54:49 +0000 Received: by pbbrp8 with SMTP id rp8so6974635pbb.19 for ; Sat, 16 Jun 2012 23:54:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-type:x-mailer:content-transfer-encoding:mime-version :x-gm-message-state; bh=mNVjxM2CnXbAVi3tCcLTqj9tR8nsN5Q4VjmWWgikp1w=; b=bkDmUTmhUtqCZ1zUoft+/3jCBVrlGmDdrKnBJ5s0eVEFt1ZnYENNQgS2X3pCB+rR2G 4abX8m5y5oyA6OXvgO8wNSxBqH+HLnwd9tm2acGb3aQ5wtDFR0gOHxD75Zj1ZTTsoeB9 5WY4znt8r3C23arUwkpLVyssP7/Mkp9G58eYorEPOT4BqI7a3bl/IxT3F7IQD3Hsl5Nd IIvh8EmKJ6UbaDWcfiIw6hC70rBp3IpgszuVlssHKtlH50YE9U3axfgL6Kt/lp7nktP7 ZTRzQ6VTDDl0ZWUIeXxSR33YzjA6iVwsyU19vX2eGlpgtJkxbsF5ks23WbZ4fB++5q2s 1IAw== Received: by 10.68.242.162 with SMTP id wr2mr38410013pbc.125.1339916074492; Sat, 16 Jun 2012 23:54:34 -0700 (PDT) Received: from [192.168.1.101] (c-69-181-249-16.hsd1.ca.comcast.net. [69.181.249.16]) by mx.google.com with ESMTPS id iu6sm19350973pbc.35.2012.06.16.23.54.33 (version=SSLv3 cipher=OTHER); Sat, 16 Jun 2012 23:54:33 -0700 (PDT) Message-ID: <1339916075.15719.38.camel@jdavis> Subject: Re: [PATCH] Support for foreign keys with arrays From: Jeff Davis To: Gabriele Bartolini Cc: PostgreSQL-development , Marco Nenciarini Date: Sat, 16 Jun 2012 23:54:35 -0700 In-Reply-To: <4EB3DF02.4020604@2ndQuadrant.it> References: <4EB3DF02.4020604@2ndQuadrant.it> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.2- Content-Transfer-Encoding: 7bit Mime-Version: 1.0 X-Gm-Message-State: ALoCoQlLf5H7wdwIWlUW+JA/XAKctnhfX/B6chGWU5lMUbpSqH+Gcn5agYDVnDQB4B5insD15wCQ X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201206/819 X-Sequence-Number: 209659 On Fri, 2011-11-04 at 13:48 +0100, Gabriele Bartolini wrote: > This patch adds basic support of arrays in foreign keys, by allowing to > define a referencing column as an array of elements having the same type > as the referenced column in the referenced table. > Every NOT NULL element in the referencing array is matched against the > referenced table. I'm trying to find commonalities between this feature and my future RANGE FOREIGN KEY feature (not past the hand-waving stage yet). The first thing I observe is that my idea for range foreign keys is almost the opposite of your idea for array FKs. I was imagining a range FK to mean that the referencing side is contained by the referenced side. This is the common definition in the temporal world, because the valid period for the referencing row must be within the valid period for the row it references (same for transaction time). The referenced side must be a range, and the referencing side must be either a range of the same type or the subtype of the range. Other similar definitions exist by replacing "contained by" with some other operator, though the use cases for those aren't as clear to me. This definition works for arrays and possibly many other types (geometry?) as well. It looks like this is orthogonal from your work, but it does seem like it has potential for confusion in the future. Thoughts? Regards, Jeff Davis