python - Can I use a trigger to add combinations of foreign keys? -
i'm in situation want multiples inserts on table trigger after insert.
here python code understand objective first:
d = dict() d["table1"] = ["1", "2"] d["table2"] = ["a","b"] itertools import product d["table12"] = [ (t1,t2,-1) t1, t2 in product(d["table1"], d["table2"])]
here result: table12 product of values of d.
{'table1': ['1', '2'], 'table2': ['a', 'b'], 'table12': [('1', 'a', -1), ('1', 'b', -1), ('2', 'a', -1), ('2', 'b', -1)]}
using database i'm trying have same behavior trigger, , complete association combinations of primary keys.
table1: pk name1 varchar table 2: pk name2 varchar table 12: pk (name1, name2) val integer fk (t1_name) reference table1 (name1) fk (t2_name) reference table2 (name2) create trigger table1_insert after insert on table1 each row begin insert table12 values(new.name1, #?, -1) end
is there way product #? like
insert table12 values(new.name2, table2.name2, -1) select * in table2;
if "3" inserted in table1: table12 must completed (3, 'a', -1), (3, 'b', -1).
use select
query in insert
query.
create trigger table1_inisert after insert on table1 each row begin insert table12 (name1, name2, val) select new.name1, name2, -1 table2 end
Comments
Post a Comment