5. Given the function
$$
f(x)=\log _{a}\left(a x^{2}-x+\frac{1}{2}\right)
$$

is always positive in the interval $[1,2]$. Then the range of the real number $a$ is . $\qquad$
5. $\left(\frac{1}{2}, \frac{5}{8}\right) \cup\left(\frac{3}{2},+\infty\right)$.

When $a>1$, the function is monotonically increasing in the interval $[1,2]$, so
$$
f(1)>0 \Rightarrow a>\frac{3}{2} \text {. }
$$

When $\frac{1}{2}<a \leqslant 1$, the function is monotonically decreasing in the interval $[1,2]$, so
$$
f(2)>0 \Rightarrow a<\frac{5}{8} \Rightarrow \frac{1}{2}<a<\frac{5}{8} .
$$

When $0<a \leqslant \frac{1}{2}$, $a-1+\frac{1}{2} \leqslant 0$, i.e., when $x=1$, $f(x)$ is undefined.
In summary, $a \in\left(\frac{1}{2}, \frac{5}{8}\right) \cup\left(\frac{3}{2},+\infty\right)$.