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:
PostgreSQL 9.3 development: Array ELEMENT Foreign Keys
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:
Foreign key constraint on array member?
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.
trialsis about. If you manage to describe this in English (as opposed to any programming (pseudo)language), as DeadEye asks for, it could help a lot understanding your requirements. At the same time, I'd suggest getting a good book or tutorial about relational databases and data modeling. – András Váczi Jan 21 '16 at 20:18