TITLE: $\iint f(x,y)\,dxdy$ and $\iint f(x,y)\,dydx$ exist but $f$ not integrable on $[0,1]\times[0,1]$
QUESTION [5 upvotes]: I want to look for a function $f(x,y)$, whose support is inside $[0,1]\times[0,1]$, such that $\int_0^1\!\int_0^1\!f(x,y)\,dxdy$ and $\int_0^1\!\int_0^1\!f(x,y)\,dydx$ both exist, but $f(x,y)$ is not Riemann-integrable (or Darboux-integrable) on $[0,1]\times[0,1]$.
By Riemann-Lebesgue Theorem, I know that the set of discontinuities of $f$ in $[0,1]\times[0,1]$ cannot be contained in a set of measure $0$ in $\mathbb{R}^2$, but with each fixed $x$ (or fixed $y$), the set of continuities of $f_x(y)$ or $f_y(x)$ can be contained in a set of measure $0$ in $\mathbb{R}^1$. 
I'm unable find a set of continuities in $[0,1]\times[0,1]$ that satisfy this, thus unable to find a function like this. Please help. Thank you very much.
Further question: is it possible that $\int_0^1\!\int_0^1\!f(x,y)\,dxdy=\int_0^1\!\int_0^1 \!f(x,y)\,dydx$ but $f(x,y)$ is not Riemann-integrable on $[0,1]\times[0,1]$?

REPLY [7 votes]: There are less complicated examples (at least this won't require a page! :)). Try
$$f(x,y) = \begin{cases} 1\,, & x = k/q \text{ and } y = \ell/q \text{ for some integers } k,\ell \text{ with $q$ prime} \\ 0\,, & \text{otherwise}\end{cases}\,.$$
Then each horizontal/vertical line segment contains (at most) finitely many discontinuities of $f$. But you need to do the exercise of showing the set $\{(k/q,\ell/q): k,\ell\in\mathbb N,\ q \text{ prime}\}$ is dense in $[0,1]\times [0,1]$.
Oh, and this function answers your second question. Both iterated integrals are $0$.