From the spectral theorem to the completeness relation in quantum mechanics I often heard that the eigenfunctions of a Hermitian operator form a completeness basis, as
$$
\sum_i | i \rangle \langle i | = \hat{1} \tag{1}
$$
and the mathematical foundation is the spectral theorem. The spectral theorem is
$$ 
\hat{A} = \int  \lambda  dE_{\lambda}, \hspace{3cm} (2)
$$
which in physicists' notation is (assuming discreteness)
$$
\hat{A} = \sum_a a | a\rangle \langle a| \hspace{3cm} (3)
$$
My question is: Eq. (1) is for a unit operator, which can be inserted anywhere. Eqs. (2) and (3) are for the operator $\hat{A}$, which is not a unit operator. How to transform (2) and (3) into the form (1)? Does it require some kind of scaling? (is that the projection-valued measure?) Perhaps such scaling is possible for a bounded operator and requires a more dedicated proof for an unbounded operator.
 A: The spectral theorem is that, if $A: D(A) \to {\cal H}$ is a selfadjoint operator, where $D(A) \subset {\cal H}$ is a dense subspace, then there exists a unique projector-valued measure $P^{(A)}$ on the Borel sets of $\mathbb{R}$
such that $$A = \int_{\mathbb R} \lambda dP^{(A)}(\lambda)\:.$$
As a consequence (this is a corollary or a definition depending on the procedure)
$$f(A) = \int_{\mathbb R} f(\lambda) dP^{(A)}(\lambda) \tag{1}$$
for every $f: {\mathbb R} \to {\mathbb C}$ Borel measurable. Taking $f(x) =1$ for all $x\in {\mathbb R}$ we have
$$I = \int_{\mathbb R} dP^{(A)}(\lambda)\:.$$
For selfadjoint operators admitting a Hilbert basis of eingenvectors $\psi_{\lambda, d_\lambda}$, $\lambda \in \sigma_p(A)$ and $d_\lambda$ accounting for the dimension of the eigenspace with eigenvalue $\lambda$, the identity above reads (referring to the strong operator-topology)
$$f(A) = \sum_{\lambda, d_\lambda} f(\lambda) |\psi_{\lambda, d_\lambda}\rangle\langle \psi_{\lambda, d_\lambda} |\:, \tag{2}$$
with the special case
$$I = \sum_{\lambda, d_\lambda}  |\psi_{\lambda, d_\lambda}\rangle\langle \psi_{\lambda, d_\lambda} |\:. \tag{3}$$
In summary Eqs.(1) and (2) are the central identities, Eq.(3) is just a special case.
Given an orthonormal complete basis $\{\psi_n\}_{n \in \mathbb N} \subset {\cal H}$,  one can always define ad hoc a selfadjoint operator $A$ (with no physical meaning in general) to implement the identities above:
$$A = \sum_{n \in \mathbb{N}} \lambda_n |\psi_{n}\rangle\langle \psi_{n} |$$ for a given arbitrary choice of real numbers $\lambda_n$.
The domain of $A$ is
$$\left\{\psi \in {\cal H} \: \left| \: \sum_{n} |\lambda_n|^2 |\langle \psi_n| \psi \rangle|^2 < +\infty\right. \right\}$$
