配列フィールドを外部キーとして使用できますか? たとえば、次の 2 つのテーブルがあります。
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)
);
テーブル Sales に " " などの制約を追加したいと考えていますForeign Key (Product_ids) references Purchase (Productid)
。
なんで?
例えば。7 月 1 日に電卓を 20 台、7 月 10 日にさらに 10 台購入しました。私は 7 月 13 日に 25 個の電卓を販売しましたProductids
。電卓の両方のロットを指し示すことができるはずです。これらを組み合わせると、25 個の番号になります (productid 1 から 20 個、productid 2 から 5 個)。これが配列の出番です。
に存在する値が配列に含まれていることを確認したいだけですPurchase.ProductId
。
これは達成できますか?