# Continuous extension of function given on rationals

This question occurred to me as a little lemma that allows me to prove an exercise I'm working on. I've already completed the exercise another way (the intended way), so don't worry about doing my homework for me.

Here goes: if $f:\mathbb{R} \to \mathbb{R}$ is given such that $f$ continuous at every rational, can we find a $g:\mathbb{R} \to \mathbb{R}$ such that $g$ continuous everywhere and $\left.g\right|_\mathbb{Q}=\left.f\right|_\mathbb{Q}$?

It seems obvious to me that we can, but I don't know how to proceed. For example, the Tietze-Urysohn extension theorem doesn't apply because $\mathbb{Q}$ isn't closed, so we have to get a bit fancier. Is it possible to do without getting into huge detail?

Take $$f(x)=\left\{\begin{array}{lll} x & \text{if} & x<\sqrt{2}, \\ -x & \text{if} & x\ge\sqrt{2}, \\ \end{array} \right.$$ The $f :\mathbb R\to\mathbb R$ is continuous on every rational, but there is no way to make it continuous on $\mathbb R$!
EDIT. If we knew that $f$ was locally uniformly continuous, then the sought for $g$ does exists, and it is unique!