CREATE OR REPLACE FUNCTION food600.doplnstrediskadopartnerov(
	)
    RETURNS smallint
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
BEGIN
UPDATE food600.food_dat set zadan_prn='' WHERE zadan_prn IS NULL;
UPDATE food600.food_dat set stredskup='' WHERE stredskup IS NULL;
UPDATE food600.partneri SET partner=food_dat.id_zkratka, ico=food_dat.stredskup, dic=food_dat.zadan_prn FROM food600.food_dat WHERE partneri.c_partner=food_dat.c_stredisk;
INSERT INTO food600.partneri (c_partner, partner, ico, dic) SELECT c_stredisk as c_partner, id_zkratka as partner, stredskup as ico, zadan_prn as dic FROM food600.food_dat WHERE c_stredisk<0 EXCEPT SELECT c_stredisk as c_partner, id_zkratka as partner, stredskup as ico, zadan_prn as dic FROM food600.food_dat INNER JOIN food600.partneri ON food_dat.c_stredisk=partneri.c_partner;
RETURN 1;
END
$BODY$;
