CREATE TABLE orders (
id SERIAL PRIMARY KEY,
productid INTEGER[] NOT NULL,
amount INTEGER[] NOT NULL,
totalprice FLOAT NOT NULL,
ordertime TIMESTAMP NOT NULL,
FOREIGN KEY (productid) REFERENCES products(id)
);
I was trying to create a table to record orders. Since that one order may contain more than one product, I plan to use an array to record the productids of every product, same thing with amount. However when I want to make the productid a foreign key which references the id attribute of table product, I found that productid is an array but products(id) is just one number. How can I solve this to make every element of the productid array reference the products(id)?? I am using postgresql btw.
Thx adhead!