בקש קהלת למצא דברי-חפץ וכתוב ישר דברי אמת
Koheles sought to find desired sayings, and genuine recorded words of truth
The custom on Sukkos is to read from the book of Koheles, otherwise known as Ecclesiastes. Various reasons are provided for this. One is that the festival of Sukkos is one of joy, and Ecclesiastes cautions us about the dangers of unbridled joy. The work is attributed to King Shlomo. Indeed, the classical understanding is the protagonist Koheles is none other than King Shlomo himself. Regarding one verse, Chazal share a cryptic interpretation. Koheles, namely King Shlomo, desired to be like Moshe. However, a Heavenly voice proclaimed “וכתוב ישר דברי אמת”, literally: it is written straight, words of truth. What does this teaching mean?
We are taught that if Moshe had entered the land of Israel, the Holy Temple would have never been destroyed. It’s obvious then that King Shlomo, who actually built the Temple, would want to be like Moshe. He of course would never want to see his handiwork destroyed. However, it would seem that the destruction of the Temple, and the resulting exile, were preordained.
When Moshe was initially tasked with being the savior of the Jewish people, he asked Hashem what His name was. Moshe said that the people will want to know who sent him. Hashem responded אקיה אשר אקיה, literally: I will be what I will be. The accepted interpretation is that Hashem was saying: “Just like I am with them in this exile, so too I will be with them in another exile”. If so, King Shlomo had no hope of preventing his Temple from being destroyed. It was already etched in Hashem’s name itself that there would be an exile.
However, the Mekubalim, those steeped in Judaism’s mystical texts, teach that the name אקיה multiplied by itself has the same numerical value as the word אמת, truth. Perhaps then this is all Hashem meant to Moshe. Who sent Moshe on this quest? אקיה אשר אקיה, which really means אמת, truth. Hashem’s seal is truth, and that is Who sent Moshe to save the nation.
This is what King Shlomo was thinking. It’s not perforce that there will be another exile. Perhaps Hashem merely meant to tell the people that His name was אמת. That could mean then that King Shlomo could be like Moshe. Just like if Moshe entered the land, the Temple would have never been destroyed, so too because King Shlomo built it, it will never be destroyed.
Alas, the Heavenly voice told him that it was not to be. וכתוב ישר דברי אמת. The Torah is written straight. If it were true that Hashem was telling the Jews that His name was אמת, it would have said so explicitly. What was the need for this math puzzle of אקיה אשר אקיה? It can’t be the intent was to tell them that His name is אמת. The only other explanation is then that Hashem will be with the Jews not only in the Egyptian exile, but also in another exile. That means the Temple would be eventually be destroyed. King Shlomo sought to be like Moshe, but in the end, it was not meant to be.
 Based on Chasam Sofer’s Derashos I p. 52 col. 1 s.v. ביקש קהלת
 Ecclesiastes 12:10
 This custom seems to postdate Chazal, as Ecclesiastes is excluded from Soferim 14:3. Some sources for this custom include Darkei Moshe to Tur Orach Chaim 663 § 2, citing Maharil Seder Tefillas Chag HaSukkos § 2. It’s also brought by the Machzor Vitri Seder Sukkos UShemini Atzeres § 10
 Magen Avraham to Shulchan Aruch Orach Chaim 490:9 § 8
 Megillah 7a; Shir HaShirim 1:1
 Bamidbar Rabbah 10:4; Shir HaShirim loc. cit.; Koheles Rabbah 1:1. This is also the understanding of the upcoming teaching
 Rosh Hashana 21b
 I’m at a loss to understand how the gemarra got this from the above verse. See Torah Temimah ad. loc. who attempts to find the justification. See also Rabbeinu Chananel ad. loc., who quotes Isaiah 42:21 (perhaps his version of the gemarra had this), which could make the derivation a little easier to understand
 The gemarra concludes with the verse ולא קם נביא עוד בישראל כמשה (Deuteronomy 34:10). Taking this into account, the gemarra is simply saying the verse in Ecclesiastes is referring to the Torah in a poetic way. It is saying that it is written in the Torah that there will be no prophet like Moshe, declining King Shlomo’s wish to be like him (Rabbeinu Chananel ad. loc.). However, the Chasam Sofer will try to explain the gemarra without this final part. See Derashos I p. 46 col. 3 s.v. בקש קהלת, where the Chasam Sofer quotes the gemarra in full and gives a different explanation
 The Chasam Sofer quotes this from Chazal. This is an oft-quoted idea whose source is hard to pinpoint. There’s a Midrash which apparently says this and is cited by the Ohr HaChaim to Deuteronomy 1:37. It’s also cited by the Parshas Derachim § 8. The earliest source I found which brings this unknown Midrash is the Toras HaMincha parshas Vaeschanan § 67. Perhaps the Midrash they’re quoting is Devarim Rabbah (Lieberman ed.) to Deuteronomy 3:6, although it’s worded differently than they how bring it. Additionally, without citing a source, the Seforno to Deuteronomy 1:37, 3:26, and 34:4 and Maharal in Netzach Yisroel Chapter 33 (see fn. 70 in the Machon Yerushalayim edition) say that if Moshe brought the Jews into the land, they never would have been exiled. See also Megaleh Amukos § 20, 84 and Nachal Kadumim Masei § 3. As well, see Zohar III parshas Pinchas p. 221a
 Exodus 3:14
 Rashi ad. loc., quoting Berachos 9b
 The Chasam Sofer doesn’t say who he is quoting. I couldn’t find any explicit source for this idea. However, see Orchos Tzadikim Sha’ar HaEmes, who writes that he “found” that אקיה אשר אקיה is connected to Hashem’s seal of אמת. The Imrei Emes, in his comment to Pardes Yosef to Exodus 3:14 § 78, cites this as well, and says this is the intent of the piyut we say in Mussaf of Rosh Hashana and Yom Kippur which begins with האוחז ביד. It says: וכל מאמינים שהוא דין אמת, ההגוי באקיה אשר אקיה. See also Ramban’s HaEmunah VeHaBitachon, which also seems to connect אקיה אשר אקיה to אמת
 אקיה  * אקיה  = אמת 
 Yoma 69b