Let $(X,\Sigma, \mu)$ a general measure space, and $\mathcal B$ the Borel $\sigma$-algebra on the extended real line $\overline{\mathbb R}$. Let $$f,g:X \to \overline{\mathbb R}$$ be two measurable functions such that $\int f d\mu$ and $\int g d\mu$ both exist (by which I mean that $f^+,f^-$ cannot both integrate to zero and similarly for $g$). Assume furthermore that
$$\int_A f d\mu = \int_A g d\mu$$
for all $A \in \Sigma$. My question is: is it then true that $f=g$ almost everywhere on $X$?
I know how to show this in the case $f,g$ are almost everywhere finite-valued and integrable. However, even if $f,g$ are a.e. finite valued, we still cannot just simply take the difference of the integrals $f,g$ because they might both be infinite. So is this actually true? If not in the general case, is it true when $\mu$ is $\sigma$-finite?
Motivation: The whole thing started by me reading Jensen's inequality: if $\phi:\mathbb R \to \mathbb R$ is convex, and $X$ an integrable random variable on a probability space $(\Omega, \Sigma, \mathbb P)$, and $\mathcal G \subset \Sigma$ a sub-$\sigma$-algebra, then we have: $$\phi(\mathbb E[X|\mathcal G]) \leq E[\phi(X)|\mathcal G]$$ The problem here is that $\phi(X)$ might not be integrable. The usual proof of existence of $E[X|\mathcal G]$ uses the Radon-Nikodym theorem, assuming $X$ is integrable. However, exercise 2.4.6 from Cohen's measure theory states the following:
Show that the assumption that $\nu$ is $\sigma$-finite can be removed from Theorem 4.2.2 if $g$ is allowed to have values in $[0,+\infty]$.
Theorem 4.2.2 is the "usual" Radon-Nikodym theorem for positive measures.
Now using this exercise and Hahn decomposition for signed measures, existence of $\mathbb E[X|\mathcal G]$ is easy, but uniqueness relies on my question above. Even uniqueness in the Exercise would require that the question I pose has a positive answer.
Final remark: $X$ of course is assumed to be finite valued, but it made me wonder about the general case above.
UPDATE: I thought about it and have a proof in the case where $\mu$ is $\sigma$-finite. Sketch:
Step 1: Assume $f,g \geq 0$ and $\mu$ is finite. Set $A_n = \{x| f(x) \leq n\}$ for $n \geq 1$. Then it is easy to see that $f = g$ a.e. on $A_n$. So $f=g$ a.e. on $\{x|f(x) \neq \infty \}$. Let $B = \{x|f(x) = \infty \}$ and $A \in \Sigma$ have finite measure. Then $$\int_{B \cap A} g d\mu = \int_{B \cap A} f d\mu \geq n\mu(B \cap A),$$ so $\int_{B \cap A} (g-n) d\mu \geq0$ and $g\geq n \text{ a.e. on } B \cap A$. By $\sigma$-finiteness we get $g\geq n \text{ a.e. on } A$, so $$g = \infty = f \text{ a.e. on } A$$
Step 2: Assume still $f,g\geq0$ but now $\mu$ is $\sigma$-finite. Then easy to use the previous to deduct $f=g$ a.e.
Step 3: Now for the general case, note that for all $A \in \Sigma$ the assumption implies that $$\int_A(f^++g^-)d\mu = \int (f^-+g^+)d\mu$$ so by Step 2 we get $$f^++g^-=f^-+g^+ \text{ a.e.}$$ which is what we want.
In lieu of that, my updated question is: is the assumption on $\sigma$-finiteness necessary? If yes, how do we prove it, if no, can you give a counterexample?
Yes if the measure space is finite, in particular yes for a probability measure, which may be all you care about. Also yes in a $\sigma$_finite space. But since you specify a general measure space, it's no in general:
Say $X=\{0\}$ and $\mu(X)=\infty$. Let $f(0)=1$, $g(0)=2$.