title: Not able to use query results inside Javascript UDF in Snowflake
body: <p>Thankyou for your time.</p>
  
  <p>I am working on a problem in Snowflake database. I am basically trying to create a Javascript UDF like following -</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION getACity()   
  RETURNS STRING   
  LANGUAGE JAVASCRIPT   
  AS 
  'function getCity() {
  var str;
  $$  str = select * from CITY where name="Laflin" //This is the problem 
  $$
  return str;   
  }';
  </code></pre>
  
  <p>As you can see I am trying to use data from another table in my function, but its not happening and I get following error - </p>
  
  <blockquote>
    <p>JavaScript compilation error: Uncaught SyntaxError: Unexpected
    identifier in getACity at ' str = select * from CITY where
    name="Laflin"' position 21</p>
  </blockquote>
  
  <p>I understand the syntax I am using to execute a query inside a javascript function is not correct, but I am not even sure if it is possible in Snowflake.</p>
  
  <p>I have following questions - </p>
  
  <ol>
  <li>Can I execute a query inside a javascript UDF and use the results in ongoing function ?</li>
  <li>Can I call a Javascript UDF inside another Javascript UDF ? If this is possible it will work for me as well.</li>
  </ol>
  
  <p>I have gone through Snowflake <a href="https://docs.snowflake.net/manuals/sql-reference/sql/create-function.html" rel="nofollow noreferrer">documentation</a> but could not find any help specific to this case.</p>
  
  <p>Thankyou again for your time. Much appreciated !</p>