There are 3 tables tab1 , tab2 , tab3 . In the tab2 table, the tab2 foreign key is the id_tab1 table tab1 ; in tab3 table tab3 foreign key id_tab2 is the id the tab2 table.
You need to make a stored function with the input parameters id_tab1 , id_tab2 and value , which will update the data tab3 in the table tab3 value value . If there is no such entry in the tab3 table, then you need to create it.
Tell me how to implement it.
- Is that mysql? Why do I need a stored procedure? - cyadvert
- need to read manuals, and there are many of them in Russian. but about the store is the right decision, you just need to read. - Vadim
- 2tag the appropriate server. MS SQL, Oracle, MySQL? - PashaPash ♦
|
1 answer
The function accepts 3 id_tab1, id_tab2 and value parameters
CREATE FUNCTION insval(integer,integer,character) RETURNS integer AS DECLARE i integer; BEGIN if exists( select 1 from tab3 where id_tab2=$2) then begin update tab3 set value = $3 where id_tab2=$2; i:=0; end; else begin insert into tab3(...) values (...$3); i:=1; end; endif; END; 'LANGUAGE plpgsql; i to determine the action if necessary
|