Expressing a metric as a sum of (possibly) many squares Given a Riemannian manifold $M$ whose metric $g$ has zero curvature, it is known that we can find local coordinates $x^i$ such that 
$$g=\sum_{i=1}^{\dim(M)}(dx^i)^2.$$
Conversely, if the curvature of a metric $g$ is non-zero, we cannot find a coordinate system where $g$ takes this "sum of squares" form. 
In spite of this result, and for a general metric $g$, is it possible to find a sequence of functions $\{f_j\}_{j\in\mathbb{N}}$ such that
$$g=\sum_{j\in\mathbb{N}}(df_j)^2?$$
If no, then what is the obstruction to there being such a sequence?
 A: The answer to your first question is yes. If you look at Spivak's 5-volume Differential Geometry text, this is proven several times in Volume II; he refers to it as "The Test Case." If you know the basics of differential geometry with differential forms, I can easily show you a proof for $\dim M = 2$, but higher dimensions require some version of the Frobenius Theorem.
A: This looks like it follows immediately from the Nash embedding theorem.
Namely, let $f : M \to \mathbb{R}^N$ be a smooth isometric embedding (whose existence is guaranteed by Nash); write $f = (f^1, \dots, f^N)$. The statement that $f$ is an isometric embedding means exactly that the metric $g$ on $M$ is the pullback by $f$ of the metric $\sum_{i = 1}^N (d x^i)^2$ on $\mathbb{R}^N$, that is,
$$
  g = f^* \Big(\sum_{i = 1}^N (dx^i)^2\Big) = \sum_{i=1}^N f^*(dx^i)^2 = \sum_{i=1}^N (df^i)^2.
$$
In particular, letting $m = \dim M$, the bound in the Nash embedding theorem applies to show it can be done with $N \leq m(m+1)(3m+11)/2$ functions $f^i$.
