CREATE OR REPLACE FUNCTION food600.f_zmeny_auto_cas(
	ip_tab character,
	ip_cdata bigint)
    RETURNS integer
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
declare zalozena boolean;
BEGIN


select EXISTS  (select idriadok from  food600.s_zmeny where tab = ip_tab and c_data = ip_cdata) into zalozena;

if zalozena THEN
 update food600.s_zmeny set zmena = now() where tab = ip_tab and c_data = ip_cdata;
else
 insert into food600.s_zmeny (zmena,tab,c_data) values (now(),ip_tab,ip_cdata);
end if ;

return 1;
END
$BODY$;
