We prove some results on when functions on compact sets K⊂C can be approximated by polynomials avoiding values in given sets. We also prove some higher dimensional analogues. In particular we prove that a continuous function from a compact set K⊂Rn without interior points to Rn can be uniformly approximated by a polynomial mapping avoiding values in any given countable set A⊂Rn, giving a real n-dimensional analogue of a recent version of Lavrentiev's theorem of Andersson and Rousu. We also prove the same result for infinite dimensional Banach spaces.