David desires deliverance not only for his own personal welfare, but for the glory of God. David says, “In your righteousness bring my soul out of trouble!” In other words, he rightly recognizes that if the Lord chooses to rescue him from his enemies, it will be due to two things: Mercy & Righteousness. Mercy toward David, because he too is a sinner. And righteousness towards his enemies who deserve God’s judgment. Therefore, David asks the Lord to “teach [him] to do [God’s] will.” This request is not made so that David can earn God’s favor by his own obedience, but so that David might at least grow in obedience to the point where God’s judgment on his enemies (and choice to spare David) will be viewed as a “righteous” (just) act on God’s part.