Can we have an Array field as a Foreign Key? For example, I have following two Tables :
Create Sequence Product_id_seq start with 1 increment by 1;
Create Table Purchase (
Productid integer default next value for product_id_seq,
Qty integer,
cost decimal(17,2)
);
Create Sequence InvoiceNo_seq start with 1 increment by 1;
Create Table Sales (
Invoice_Number integer default next value for InvoiceNo_Seq,
qty integer,
product_ids ARRAY,
sale_value decimal(17,2)
);
I would like to add a constraint in table Sales such as "Foreign Key (Product_ids) references Purchase (Productid)".
Why?
eg. I purchased 20 Calculators on 1st July and Another 10 on 10th July. I sold 25 Calculators on 13th July, I should be able to point to the Productids of both the lots of Calculators, combining which they become 25 Nos (20 from productid 1 and 5 from productid 2). this is where array comes into picture.
I Just want to make sure that the Array Contains Values which are present in Purchase.ProductId.
Can this be Achieved?