Re: [PATCH] Support for foreign keys with arrays - Mailing list pgsql-hackers

From Jeff Davis
Subject Re: [PATCH] Support for foreign keys with arrays
Date
Msg-id 1339916075.15719.38.camel@jdavis
Whole thread Raw
In response to [PATCH] Support for foreign keys with arrays  (Gabriele Bartolini <gabriele.bartolini@2ndQuadrant.it>)
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Amit kapila
Date:
Subject: Re: Allow WAL information to recover corrupted pg_controldata
Next
From: Simon Riggs
Date:
Subject: Re: Broken system timekeeping breaks the stats collector