Re: Array of foreign key

From: Corey Taylor <corey(dot)taylor(dot)fl(at)gmail(dot)com>
To: Daevor The Devoted <dollien(at)gmail(dot)com>
Cc: Thomas Poty <thomas(dot)poty(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Array of foreign key
Date: 2017-12-24 08:53:24
Message-ID: CADBz385zgxOpK1DdM1Me73=a1DE+D6hUqb=DM+e9wPpoSsH7BQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Dec 24, 2017 at 1:11 AM, Daevor The Devoted <dollien(at)gmail(dot)com>
wrote:

>
> Le 23 déc. 2017 20:25, "Peter J. Holzer" <hjp-pgsql(at)hjp(dot)at> a écrit :
>
> I think the OP wants something like this:
>
> create table features (
> id serial primary key,
> name varchar not null
> );
>
> create table products (
> id serial primary key,
> name varchar not null,
> array_of_features int[]
> references [] features(id) -- XXX - invented syntax
> );
>
> where products.array_of_features can only contain integers from
> features.id. This doesn't currently (as of 10.1) work.
> As I wrote, you could use triggers, but there is no way to declare that
> foreign key directly.
>
>
> This is an interesting feature you are talking about. However, I'm not
> sure I properly understand the use-case(s). Could you perhaps please give
> some examples to help me understand? (I don't just mean some SQL code, I
> mean an explanation of the business use-cases served by the code).
>

Other than Peter's simple example above, you could implement a simple RBAC
system this way. As with the features example above, you would have a
table of roles that are referenced by a user table. In this case, you
would need an int array with foreign key constraints on each element in
the array to the id column in the role table.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2017-12-24 12:02:03 Re: Array of foreign key
Previous Message Daevor The Devoted 2017-12-24 07:11:46 Re: Array of foreign key