I remember seeing that code snippet on my blog post at this link: .
In a nutshell, it's important to run this code within the appropriate context, especially the part that deals with error handling.
This piece of code should be integrated and executed alongside a necessary Query
class, even though it may be simplistic in nature.
The parameter query
represents an instance of that basic class. Its constructor must include a SQL statement for initialization. If there are any errors while running the SQL, you can access them as follows:
class Query{
constructor(statement){
this.statement = statement;
}
var out = {};
var query = getQuery(sqlStatement);
if (query.error == null) {
return rsToJSON(query);
} else {
return {"error": query.error};
}
Furthermore, there is another portion of the code sample that updates the Query class with any error details:
function getQuery(sql){
var cmd = {sqlText: sql};
var query = new Query(snowflake.createStatement(cmd));
try {
query.resultSet = query.statement.execute();
} catch (e) {
query.error = e.message;
}
return query;
}
If you place this block of code before the rsToJSON function, it will help identify any SQL errors that occurred.