On Sun, Dec 24, 2017 at 1:11 AM, Daevor The Devoted <doll...@gmail.com> wrote:
> > Le 23 déc. 2017 20:25, "Peter J. Holzer" <hjp-pg...@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.