do $$
BEGIN
IF EXISTS (SELECT * FROM usages WHERE project_id = :projectId AND entity_id = :entityId) THEN
  UPDATE usages SET usages = usages + :usages WHERE project_id = :projectId AND entity_id = :entityId;
ELSE
  INSERT INTO usages (project_id, entity_id, usages) VALUES (:projectId, :entityId, :usages);
END IF;
END;
$$