The writer of Eccelesiastes in the Bible was aware of some of the psalms, and mocked them.
Consider these two verses. First, Psalm 37:25:
I have been young, and now am old, yet I have not seen the righteous forsaken, or their children begging bread.
Then, Ecclesiastes 7:15:
In my vain life I have seen everything: there are righteous people who perish in their righteousness, and there are wicked people who prolong their life in their evildoing.
I think the parallels between these two verses are too great for this to be coincidence. Qoheleth had read the psalm, and said that it is Wrong.
If the Bible is inspired by God, this cannot mean that it is inerrant, because it contradicts itself. Rather, it is human beings struggling to express the truth as best they may understand it, struggling with life and with setbacks: how can God’s Chosen People be invaded and conquered? Sometimes, they get it wrong in an interesting way.
Sometimes, in wrestling with the contradictions and the bits I do not like, I gain a greater understanding. A good example is Psalm 137:8-9:
Happy shall they be who pay you back for what you have done to us! Happy shall they be who take your little ones and dash them against the rock!
Killing babies. There are schemes for praying the psalms over a period which omit the cursing psalms, of which this verse is one of the most shocking. And yet, having been aware of it for a time, I find it one of my favourite verses. I find it reassuring. The very depths of human rage and despair are expressed here, and so in some way found acceptable. Even when I am swallowed whole by misery and anger, I am not rejected by God.