This question already has an answer here:
- Foreign key constraint on array member? 3 answers
I have a table:
CREATE TABLE methods ( method_id serial PRIMARY KEY, method_name varchar(100) );
I now want to create a table with the following columns:
CREATE TABLE experiments ( method integer REFERENCES methods(method_id), trials integer );
I get an error:
Key columns "method" and "method_id" are of incompatible types: integer and integer.
I understand that the columns have to be the same type and I also saw that some tried to tackle this foreign key on array issue already:
My interest is that 'method' should be an array of integers referencing 'method_id' from table 'methods' but I can't figure it out. I thought that the link above might be a solution, but seems that was not implemented (?)
Some posts propose using junction/join tables:
I am an absolute beginner and I could not figure it out yet. For me, it is a matter of understanding first how to tackle this issue of a foreign key on an array. Multiple methods can be considered as forming a class of methods. Each class can have a certain number of trials.