If $R$ is a ring and $J\subset R$ is an ideal, can $R/J$ ever be a flat $R$-module? For algebraic geometers, the question is "can a closed immersion ever be flat?"

The answer is yes: take $J=0$. For a less trivial example, take $R=R_1\oplus R_2$ and $J=R_1$, then $R/J$ is flat over $R$. Geometrically, this is the inclusion of a connected component, which is kind of cheating. If I add the hypotheses that $R$ has no idempotents (i.e. $\operatorname{Spec}(R)$ is connected) and $J\neq 0$, can $R/J$ ever be flat over $R$?

I think the answer is no, but I don't know how to prove it. Here's a failed attempt. Consider the exact sequence $0 \to J\to R\to R/J\to 0$. When you tensor with $R/J$, you get

$$ 0 \to J/J^2 \to R/J \to R/J \to 0 $$

where the map $R/J\to R/J$ is the identity map. If $J\neq J^2$, this sequence is not exact, contradicting flatness of $R/J$.

But sometimes it happens that $J=J^2$, like the case of the maximal ideal of the ring $k[t^q| q\in\mathbf Q_{>0}]$. I can show that the quotient is not flat in that case (see this answer), but I had to do something clever.

I usually think about commutative rings, but if you have a non-commutative example, I'd love to see it.