Note: An answer has already been accepted, (which cites tradition/Rashi), this answer is submitted as an alternate, with the intent to rely exclusively on the text.
1. Question Restatement
In Eccl. 1:18, Does Solomon say that increasing in knowledge generally brings sorrow, and just that specific knowledge, like knowledge regarding the vanity of things?
Ecclesiastes 1:18, NASB - Because in much wisdom, (חָכְמָ֖ה) there is much grief, and increasing knowledge, (דַּ֖עַת), results in increasing pain.
2. Answer
The Writer's analysis of the Pursuits of Men, including the Pursuits of Wisdom and Knowledge, do not end in conclusion that only Wisdom brings grief, or that only knowledge brings pain--throughout the book, the writer affirms that they BOTH inevitably lead to vanity--that all pursuits do :
Eccl. 7:2-3, NASB - It is better to go to a house of mourning Than to go to a house of feasting, Because that is the end of every man, And the living takes it to heart. 3 Sorrow is better than laughter, For when a face is sad a heart may be happy.
The Book of Ecclesiastes is an "Argument", that even the Most Noble of Pursuits, (like wisdom and knowledge) inevitably lead to sorrow, loss, and judgment, including the pursuit of Wisdom and Knowledge--with TWO exceptions, (the fear of God, and trusting in obedience).
Eccl. 12:13, NASB - The conclusion, when all has been heard, is: fear God and keep His commandments, because this applies to every person. 14 For God will bring every act to judgment, everything which is hidden, whether it is good or evil.
3. The Knowledge that Brings Grief, is Great Knowledge
The verses immediately before explicitly state that this knowledge was not limited to knowledge of just one thing, but rather Knowledge that is great in Width, AND Depth, about MANY things.
Eccl. 1:16, NASB - I said to myself, “Behold, I have magnified and increased wisdom more than all who were over Jerusalem before me; and my mind has observed a wealth of wisdom and knowledge.”
Eccl. 12:9, NASB - In addition to being a wise man, the Preacher also taught the people knowledge, [certainly not of just one thing]; and he pondered, searched out and arranged many proverbs.
4. Joy is not Mutually Exclusive with Wisdom/Knowledge
The writer again sets apart joy, as distinct from wisdom and knowledge.
Joy is given, and found, as a divine gift, apart from pursuits.
Eccl 2:26, NASB - For to a person who is good in His sight He has given wisdom and knowledge and joy, while to the sinner He has given the task of gathering and collecting so that he may give to one who is good in God’s sight. This too is vanity and striving after wind.
6. The Context: Pursuit of God
In context of Ecclesiastes, the writer is certainly attempting to show which pursuits of man, which works, are least "vain".
This examination even includes the pursuit of Wisdom and Knowledge.
In the end, the writer concludes stating that EVERY work will be brought into judgment--including the pursuit of knowledge and wisdom!
The writer concludes, declaring that there are--two things--that man can confidently pursue: fearing God, and obeying his Commandments.
However, "Fear and Obedience" are not "the end", but rather a "spoke" on a cyclical pattern in the pursuit of God, that leads to more knowledge, and wisdom, to fear--back again to obedience, to more understanding, etc ...
Job 28:28 - “And to man He said, ‘Behold, the fear, (יִרְאַ֣ת) of the Lord, that is wisdom, (חָכְמָ֑ה); And to depart from evil, [obey], is understanding, (בִּינָֽה).’”
But this process cannot begin without obedience and trust.
Prov. 2:1, NASB - My son, if you will receive my words, [listen] And treasure my commandments within you, [obey] 2 Make your ear attentive to wisdom, Incline your heart to understanding, [humility]; 3 For if you cry for discernment, Lift your voice for understanding; 4 If you seek her as silver And search for her as for hidden treasures, [seeking]; 5 THEN you will discern the fear of the Lord And discover the knowledge of God.
7. Issues
- This question exhibits a "False Dilemma", leading one to presuppose that the writer is only speaking of, either: (A.) sorrow/pain that comes from the knowledge that these pursuits are vain; Or, (B.) if the writer is speaking of the sorrow/pain that comes from knowledge in general.
- A third possibility, that the writer was making a judgment about Wisdom AND Knowledge AND Everything Else; Was the writer having a "bake-off", trying to identify the best pursuit(s), ones that don't lead to sorrow or grief?
- Is the writer discouraging the pursuit of great wisdom and knowledge, in general?
- The writer compares/contrasts different values throughout the book, which one(s) come out on top?