At first sight, verses such as these might appear to show a self-righteous attitude and perhaps that David was proud of his own righteousness. If you were to say the same things to your friends, you know how they would react! But there are two factors to consider in looking at verses like these and understanding what David meant:
1) What righteousness means in the Old Testament. First, we must understand that the concept of righteousness in the Old Testament is somewhat different from what we find today and even in the New Testament. In the Hebrew Bible the word sedek which is often translated as “righteousness” literally means “straightness” as opposed to “crookedness,” but it is usually used of the status of relationships rather than as a measure of perfection. Under the Law of Moses one could be righteous by simply maintaining one’s relationship with God and others according to basic legal norms – the term did not denote some kind of perfect purity or spiritual perfection.
Anyone who did not literally murder, cheat, lie to, or otherwise harm other individuals maintained a proper relationship with them and was therefore “righteous.” In the same way, those who, for example, did not take God's name in vain and who kept the Sabbath day maintained a basic relationship with God that was regarded as righteousness. This is different, of course, from the deeper expectations of the New Testament, which more frequently stress the spirit of the law, as well as the importance of right motivation and the attitude behind our behavior.
But according to the earlier concept of righteousness found in much of the Old Testament, when a person fulfilled the basic demands of his relationship with God and others he or she could be said to be “righteous,” and many of the times that David uses the term sedek, it is from this perspective. David was righteous in Hebrew terms simply because he lived within the expectations of the covenant community of which he was a part.
2) What David also says regarding sin and righteousness. Even though David could see himself as usually being righteous in terms of how his society used the term, we find plenty of evidence that he was not proudly self-righteous. We know that David sinned and knew that he sinned (Psalm 51, etc.), so it is clear he did not imagine himself perfect in our modern sense of righteousness. We also know that David earnestly asked God to help him walk in the way of righteousness, as we see, for example, in Psalm 19: “Keep back your servant also from presumptuous sins; let them not have dominion over me. Then I shall be blameless, and I shall be innocent of great transgression” (Psalm 19:13).
Finally, we know that beyond asking God’s help to walk righteously, David openly gave God the credit when he did do what was right! In Psalm 18 – the same psalm we quote above regarding David’s expressions of righteousness – we also find: “It is God who arms me with strength, and makes my way perfect” (Psalm 18:32). This same attitude of humbly crediting God with his righteousness is frequently confirmed in other psalms, as when David says: “You are my Lord, my goodness is nothing apart from You” (Psalm 16:2).
So, there is no indication in the psalms of David, or elsewhere, that David was self-righteous or proud of his own goodness. It is clear that while David knew that at most times he did walk righteously according to how this concept was understood in his own culture, it is equally clear that he asked God’s help to do so and gave God credit when he succeeded.
* For further understanding of the psalms of David, download our free e-book Spotlight on the Psalms from our sister site here.