Re: Array of foreign key

Поиск
Список
Период
Сортировка
От Corey Taylor
Тема Re: Array of foreign key
Дата
Msg-id CADBz385zgxOpK1DdM1Me73=a1DE+D6hUqb=DM+e9wPpoSsH7BQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Array of foreign key  (Daevor The Devoted <dollien@gmail.com>)
Список pgsql-general
On Sun, Dec 24, 2017 at 1:11 AM, Daevor The Devoted <dollien@gmail.com> wrote:

Le 23 déc. 2017 20:25, "Peter J. Holzer" <hjp-pgsql@hjp.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.

В списке pgsql-general по дате отправления:

Предыдущее
От: Daevor The Devoted
Дата:
Сообщение: Re: Array of foreign key
Следующее
От: "Peter J. Holzer"
Дата:
Сообщение: Re: Array of foreign key