Hi Jack! The query.query attribute should contain the string version of the SQL query that you wrote, as long as that query has been saved. I was able to produce a very simple example. Those things might get more complex as you move to a more complicated query.
1) You must disable prepared statements. I don't believe you'll be able to achieve the functionality you want with them enabled. You can read more about why here: https://docs.retool.com/docs/sql-queries#security
2) I created a temp state variable that will hold the value of the query.query attribute and ran another JS query to set the value of that temp state variable. 3) Then created another SQL query that pulls the value from temp state. This is the step where I believe that having prepared statements enabled would cause this setup to fail. Hope this helps!