Let
V
V
be an affine algebraic variety over
R
\mathbb {R}
(or any other real closed field
R
R
). We ask when it is true that every positive semidefinite (psd) polynomial function on
V
V
is a sum of squares (sos). We show that for
dim
V
≥
3
\dim V\ge 3
the answer is always negative if
V
V
has a real point. Also, if
V
V
is a smooth non-rational curve all of whose points at infinity are real, the answer is again negative. The same holds if
V
V
is a smooth surface with only real divisors at infinity. The “compact” case is harder. We completely settle the case of smooth curves of genus
≤
1
\le 1
: If such a curve has a complex point at infinity, then every psd function is sos, provided the field
R
R
is archimedean. If
R
R
is not archimedean, there are counter-examples of genus
1
1
.