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 tried to create a table to record orders. Since this order may contain more than one product, I plan to use an array to record the products of each product, the same with the amount. However, when I want to make productid a foreign key that references the id attribute for a table product, I find that productid is an array and products (id) is just one number. How can I solve this problem so that each element of the productid array refers to products (id)? I am using postgresql btw.
thanks adhead!
source
share