create function nic2 () returns trigger as $$
begin
  if (select count(*) from zwierzaki where gatunek = new.gatunek) > 4
  then raise exception 'Źle';
  end if;
  raise notice 'tu jestem 2';
  return new;
end;
$$ language plpgsql;

create trigger wyzwnic2
  after insert or update on zwierzaki
  for each row
  execute procedure nic2();

