Another thing is a Psalm for the dedication song. This is what the scripture says (Psalm 32:13): "The Lord's unfailing love surrounds the one who trusts in him." Rabbi Yehuda and Rabbi Nehemiah said that the measure of punishment is primary, and it does not yield good fruit, while the measure of good produces good fruit, as it says (Hosea 10:12): "Sow righteousness for yourselves, reap the fruit of unfailing love."
What does God do? He collects a person's sins and then gives them their reward. The rabbis said that even if God does not immediately collect a person's sins, as it says (Ezra 9:13): "You, our God, have punished us less than our sins deserved." Rabbi Elazar and Rabbi Yosei bar Hanina said, "The hand with the scales is like the hand with sins and the hand with merits."
And what does God do? He inclines the scales toward mercy, as it says (Psalm 32:13): "The Lord's unfailing love surrounds the one who trusts in him." Rabbi Yosei bar Hanina said, "What does God do? He snatches the bill of sins that is in one hand and the merits are immediately decided."
As it says (Micah 7:18): "Who is a God like you, who pardons sin and forgives the transgression of the remnant of his inheritance?" Rabbi Nehemiah said, "If a Gentile intends to commit a transgression, even if God did not carry it out, He considers it as if he did it." For he says (Deuteronomy 26:5), "An Aramean tried to destroy my father." But where did Laban destroy Jacob?
Rather, because he intended to do so, the scripture considers it as if he had done it. And if a non-Jew intends to perform a mitzvah, it is not written for him until he does it, as it says (Daniel 6:15), "Even until the sun rose." And the Holy One, blessed be He, did not consider it against him until he did it. And if an Israelite intends to commit a sin but does not do it, the Holy One, blessed be He, does not write it until he does it, as it says (Micah 2:1), "Woe to those who devise iniquity and work evil upon their beds."
David said, "If I had seen iniquity in my heart, the Lord would not have heard me" (Psalms 66:18). And if one intends to perform a mitzvah but is prevented from doing so, the Holy One, blessed be He, considers it as if he had done it. Know that David intended to build the Temple, and even though he did not build it, it was written in his name, as it says, "A psalm, a song for the dedication of the House, by David" (Psalms 30:1).
From this we learn that anyone who is distressed over a matter is called by his name, as we find with Moses, who was distressed over the Torah and is called by his name, as it says (Malachi 3:22), "Remember the Torah of Moses, My servant." Similarly, David, who was distressed over the Temple, is called by his name, as it says, "A psalm, a song for the dedication of the House, by David."