Rabbi Isaac opened (with Ecclesiastes 7:23): "All this I tested with wisdom." It is written (in I Kings 5:9 [4:29]): "And God gave Solomon wisdom [and so forth, like the sand which is on the seashore]." The Rabbis say: Wisdom was given to him equal to all Israel. And Rabbi Levi said: Just as the sand is a fence for the sea, so was wisdom a fence for Solomon. The proverb says: Knowledge you lack—what have you acquired? Knowledge you have acquired—what do you lack? (Proverbs 25:28): "A breached city without a wall is a man who has no restraint over his spirit." [Like a breached city that has no wall in it, so is a man who has no restraint over his spirit.]
Wisdom as Solomon's Wall and the Sand That Fences the Sea
Midrash Tanchuma Buber, Chukat 10:1
ר' יצחק פתח כל זה נסיתי בחכמה (קהלת ז כג), כתיב ויתן אלהים חכמה לשלמה [וגו' כחול אשר על שפת הים] (מ"א ה ט), רבנן אמרי ניתן לו חכמה כנגד כל ישראל, ור' לוי אמר מה חול גדר לים, כך היתה חכמה גדר לשלמה, מתלא אמר דעה חסרת מה קנית, דעה קנית מה חסרת, עיר פרוצה אין חומה איש אשר אין מעצר לרוחו (משלי כה כח), [כעיר פרוצה שאין בה חומה כן איש אשר אין מעצור לרוחו].