Is there a univariate rational polynomial which represents only squares in $\mathbb{R}$ and $\mathbb{Q}_2$, but not all other $\mathbb{Q}_p$? Let $K$ be a field; I will say a polynomial $f \in K[X]$ represents an element $a \in K$ if there exists a $b \in K$ such that $f(b) = a$.
Denote by $\mathbb{Q}$, $\mathbb{R}$ and $\mathbb{Q}_p$ the fields of rational, real and $p$-adic numbers respectively. Does there exist a polynomial $f \in \mathbb{Q}[X]$ such that


*

*$f$ represents only squares over $\mathbb{R}$ (but not all squares need to be represented),

*$f$ represents only squares over $\mathbb{Q}_2$ (but not all squares need to be represented),

*for every prime number $p > 2$, $f$ does not represent only squares over $\mathbb{Q}_p$?


If so, what is the minimal degree such a polynomial must have?
What I have found so far:


*

*A polynomial satisfying $1$ and $3$, but not $2$:
$$
1 + X^2
$$

*A polynomial satisfying $1$ and $2$ and which I think might also satisfy $3$, but I do not know how to prove it:
$$
(1 + X^2)(17 + X^2)
$$
Here, $17$ may be replaced with any positive integer with residue $1$ modulo $16$.

 A: Clearly degree 1 and 3 polynomials do not satisfy property 1.
The only degree 2 polynomials in $\mathbb{Q}[X]$ with property 2 are squares. To verify this, after a possible change of variables assume that $aX^2+b$ is a polynomial generating only squares over $\mathbb{Q}_2$ with $b\ne 0$.  By setting $X=0$ we know $b$ is a square in $\mathbb{Q}_2$, so multiplying by $b^{-1}$ we can assume $b=1$. Next, write $a=2^nc$ with $n=v_2(a)$ its $2$-adic valuation, so that $c\in \mathbb{Z}_2^{\times}$. 


*

*If $n$ is even, say $n=2m$, set $X=c2^{1-m}$ to find that $4c^2+1$ is a square in $\mathbb{Q}_2$, but we reach a contradiction as $5$ is not a square modulo $8$. 

*If $n$ is odd, say $n=2m-1$, set $x=2^{-m}$ to yield that $c/2+1$ is a square in $\mathbb{Q}_2$, which is impossible because its valuation is $-1$. 


Finally, there do exist polynomials of degree 4 satisfying all three properties. In particular $f(X)=(8X^2+1)(8X^2+9)$ does the job. Property 1 is clear, so let us check property 2.
The (extended) Hensel's lemma tells you that if a polynomial in $\mathbb{Q}_2[X]$ has a root modulo 8 whose derivative at that root is not divisible by 4, then the polynomial has a root in $\mathbb{Q}_2$. Let $a\in\mathbb{Q}_2$ be arbitrary, and write $a=2^nb$ with $b\in \mathbb{Z}_2^{\times}$. When $n\ge -1$, we can apply the above to $X^2-(8a^2+1)(8a^2+9)$. When $n<-1$, we can see that $$f(a)=2^{2(2n+3)}(b^2+2^{-2n-3})(b^2+9\cdot 2^{-2n-3})$$ and thus apply Hensel's to $X^2-2^{-2(2n+3)}f(a)$. 
As for property 3 (inspired by user mercio's comment below), Let $p$ be an odd prime and suppose $f(X)$ only generates squares over $\mathbb{Q}_p$. As $f(1)\equiv 3\pmod{9}$, we can assume $p\ne 3$. Then the elliptic curve $$E:y^2=(8x^2+1)(8x^2+9)$$ has good reduction at $p$ (Wolphram tells me the discriminant is $2^{34}\cdot 9$). Under the assumption $f(x)$ is a square mod $p$ for any $x$, the number of points on $E$ must be at least $2p-4$. The Hasse bound yields at most $2\sqrt{p}+p$ points (note we ignore the point at infinity). Thus, $$2p-4\le 2\sqrt{p}+p$$ which is false for $p\ge 5$. In particular there is an $x$ with $(8x^2+1)(8x^2+9)$ not a square mod $p$, thus $f(X)$ cannot generate only squares in $\mathbb{Q}(X)$.
(Numerical data suggests in fact that more or less half of the numbers $(8x^2+1)(8x^2+9)$ for $x\in\mathbb{F}_p$ are quadratic residues). 
The polynomial suggested by the OP works as well, the proof for property three works equally well except additionally one has to exhibit a nonsquare for the prime $17$ ($x=2$ works).
A: Not an answer, but some ideas for an approach. If $(1+x^2)(17+x^2)=n^2$ for some p-adic number $n$, then we also know that $n^{-2}$ is also a square. So we can look for examples/counterexamples by inverting it as we will necessarily have a power series that satisfies the same criteria.
I begin by using partial fraction decomposition,
$$n^{-2} = \frac{1}{1+x^2}\frac{1}{17+x^2} = \frac{1}{16}\left( \frac{1}{1+x^2} - \frac{1}{17+x^2}\right)$$
As it turns out, $4^{-2}$ factors out. Since a square divided by a square is still a square, we can just focus on this difference,
$$\frac{1}{1+x^2} - \frac{1}{17+x^2}$$
Then rewrite it as a pair of power series (with the exception of $\mathbb{Q}_{17}$), as:
$$\sum_{n=0}^\infty (-1)^n x^{2n} - 17^{-1}\sum_{n=0}^\infty  (-17)^{-n} x^{2n}$$
$$=\sum_{n=0}^\infty (-1)^n [1-17^{-n-1}] x^{2n}$$
I decide to think of what values it converges for, just as wild grasping for some kind of insight to try to figure this out and recognize that part of the coefficients can be rearranged as,
$$ 1-17^{-n-1}  =  \frac{17^{n+1}-1}{17^{n+1}} = \frac{(2^4+1)^{n+1}-1}{(2^4+1)^{n+1}}$$
If I look a this limit in $\mathbb{Q}_2$ I recognize clearly,
$$\lim_{n\to \infty} \frac{(2^4+1)^{n+1}-1}{(2^4+1)^{n+1}} = 0$$
I've spent enough time blindly flailing around, but maybe this gives something useful to think about.
