Getting column name from result set using JavaScript in Snowflake?

Viewed 693

In Snowflake when we query using Javascript inside Stored procedure , we used to get Result_set . How can we get Column name of the output result using Javascript API.???

Note: I am not asking about result column values which we can get using .getColumnValue() or getColumnValueAsString function.

1 Answers

You could use getColumnName:

Stored Procedure API - Object Statement

A stored procedure Statement object provides the methods for executing a query statement and accessing metadata (such as column data types) about the statement.


getColumnName(colIdx)

This method returns the name of the specified column.

Parameters

The index number of the column (starting from 1, not 0).

For instance:

CREATE OR REPLACE PROCEDURE test()
RETURNS string
LANGUAGE JAVASCRIPT
AS
$$
    var sql_command = "SELECT 10 as col";
    var stmt = snowflake.createStatement( {sqlText: sql_command} );
    var resultSet = stmt.execute();
    return stmt.getColumnName(1);
$$;
Related