CREATE OR REPLACE FUNCTION food600.rozkopiruj_nazvy()
    RETURNS integer
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
BEGIN

update food600.karty set naz1 = nazev where naz1 is null or trim(naz1) = '';
update food600.karty set naz2 = naz1  where naz2 is null or trim(naz2) = '';
update food600.karty set naz3 = naz1  where naz3 is null or trim(naz3) = '';
update food600.karty set naz4 = naz1  where naz4 is null or trim(naz4) = '';
update food600.karty set naz5 = naz1  where naz5 is null or trim(naz5) = '';

update food600.karty set nazev1 = left(nazev, 27)  where nazev1 is null or trim(nazev1) = '';
update food600.karty set nazev2 =      nazev1      where nazev2 is null or trim(nazev2) = '';
update food600.karty set nazev3 =      nazev1      where nazev3 is null or trim(nazev3) = '';
update food600.karty set nazev4 =      nazev1      where nazev4 is null or trim(nazev4) = '';
update food600.karty set nazev5 =      nazev1      where nazev5 is null or trim(nazev5) = '';


update food600.ktexty set nazev1 = left(karty.nazev, 27) from food600.karty  where food600.karty.c_karty = food600.ktexty.c_karty and (food600.ktexty.nazev1 is null or trim(food600.ktexty.nazev1) = '') ;
update food600.ktexty set nazev2 = nazev1 where (food600.ktexty.nazev2 is null or trim(food600.ktexty.nazev2) = '') ;
update food600.ktexty set nazev3 = nazev1 where (food600.ktexty.nazev3 is null or trim(food600.ktexty.nazev3) = '') ;
update food600.ktexty set nazev4 = nazev1 where (food600.ktexty.nazev4 is null or trim(food600.ktexty.nazev4) = '') ;
update food600.ktexty set nazev5 = nazev1 where (food600.ktexty.nazev5 is null or trim(food600.ktexty.nazev5) = '') ;

update food600.ktexty set naz1 = karty.nazev from food600.karty  where food600.karty.c_karty = food600.ktexty.c_karty and (food600.ktexty.naz1 is null or trim(food600.ktexty.naz1) = '') ;
update food600.ktexty set naz2 = naz1 where (food600.ktexty.naz2 is null or trim(food600.ktexty.naz2) = '') ;
update food600.ktexty set naz3 = naz1 where (food600.ktexty.naz3 is null or trim(food600.ktexty.naz3) = '') ;
update food600.ktexty set naz4 = naz1 where (food600.ktexty.naz4 is null or trim(food600.ktexty.naz4) = '') ;
update food600.ktexty set naz5 = naz1 where (food600.ktexty.naz5 is null or trim(food600.ktexty.naz5) = '') ;

update food600.ktexty set meno1 = naz1 where (food600.ktexty.meno1 is null or length(trim(food600.ktexty.meno1)) < 9) ;
update food600.ktexty set meno2 = naz1 where (food600.ktexty.meno2 is null or length(trim(food600.ktexty.meno2)) < 9) ;
update food600.ktexty set meno3 = naz1 where (food600.ktexty.meno3 is null or length(trim(food600.ktexty.meno3)) < 9) ;
update food600.ktexty set meno4 = naz1 where (food600.ktexty.meno4 is null or length(trim(food600.ktexty.meno4)) < 9) ;
update food600.ktexty set meno5 = naz1 where (food600.ktexty.meno5 is null or length(trim(food600.ktexty.meno5)) < 9) ;


update food600.nlimit_hladiny set c_hlad = 1 where (food600.nlimit_hladiny.c_hlad is null or food600.nlimit_hladiny.c_hlad = 0) ;

RETURN 1;
END
$BODY$;
