Is there a function with infinite integral on every interval?

The easiest example I know is constructed as follows. Let $q_{n}$ be an enumeration of the rational numbers in $[0,1]$. Consider $$g(x) = \sum_{n=1}^{\infty} 2^{-n} \frac{1}{|x-q_{n}|^{1/2}}.$$ Since each function $\dfrac{1}{|x-q_{n}|^{1/2}}$ is integrable on $[0,1]$, so is $g(x)$ [verify this!]. Therefore $g(x) < \infty$ almost everywhere, so we can simply set $g(x) = 0$ in the points where the sum is infinite.

On the other hand, $f = g^{2}$ has infinite integral over each interval in $[0,1]$. Indeed, if $0 \leq a \lt b \leq 1$ then $(a,b)$ contains a number $q_{n}$, so $$\int_{a}^{b} f(x)\,dx \geq \int_{a}^{b} \frac{1}{|x-q_{n}|}\,dx = \infty.$$ Now in order to get the function $f$ defined at every point of $\mathbb{R}$, simply define $f(n + x) = f(x)$ for $0 \leq x \lt 1$.


See exercise 26 (c) on p. 327 here.