Please tell me, is it possible somehow in Postgres to specify an array as a data type that contains foreign key elements I have next table:
CREATE TABLE User
(
id SERIAL PRIMARY KEY,
name VARCHAR(50)
);
CREATE TABLE Team
(
id SERIAL PRIMARY KEY,
idOwnerTeam INT,
idTeamUsers INT[], -- PROBLEM
FOREIGN KEY (idOwnerTeam) REFERENCES User(id),
FOREIGN KEY (idTeamUsers ) REFERENCES User(id) -- PROBLEM
);
I will be grateful for any help
I know that this problem can be solved if you specify the command from the user. Then the solution will look like this:
CREATE TABLE User
(
id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
idTeam INT
);
CREATE TABLE Team
(
id SERIAL PRIMARY KEY,
idOwnerTeam INT NOT NULL,
FOREIGN KEY (idOwnerTeam) REFERENCES User(id),
);
ALTER TABLE User
ADD FOREIGN KEY (idTeam) REFERENCES Team(id);
But unfortunately this solution doesn't work for me.