CREATE OR REPLACE FUNCTION food600.davky_pridanie_novej()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE mpocet INTEGER DEFAULT 0;
	mzmena TIMESTAMP;
BEGIN
      
  IF (TG_OP = 'INSERT') THEN
    SELECT COUNT(davka) INTO mpocet from food600.davky WHERE davky.davka=NEW.davka AND davky.c_data=NEW.c_data;
    IF mpocet=0 THEN
      mzmena := current_timestamp;
      PERFORM food600.f_zmeny_tab('davky',mzmena,NEW.c_data);
    END IF;   
  END IF;
        
  RETURN NEW;
END;
$BODY$;
