1

I have a Snowflake procedure, for brevity, lets just say it just runs a query using snowflake.execute

var rs = snowflake.execute( { sqlText:
`
  CREATE OR REPLACE VIEW DATABASE.SCHEMA.VIEW_NAME_HERE AS
  SELECT
    column1
    ,${stuff}     as column2
    ,${morestuff} as column3

  FROM DATABASE.SCHEMA.TABLE_SOURCE_HERE
`

                            } );
  return rs

How do i return rs so that it shows the query that it's running? I'm just getting an [object object] result.

1 Answer 1

3

The Statement object has a method called getSqlText():

https://docs.snowflake.com/en/sql-reference/stored-procedures-api.html#getSqlText

CREATE OR REPLACE PROCEDURE my_proc() 
RETURNS STRING 
LANGUAGE JAVASCRIPT 
EXECUTE AS OWNER
AS 
$$ 
    snowflake.execute( {sqlText: "create or replace table test (col string)"} ); 
    var column = 'col';
    var stmt = snowflake.createStatement( {sqlText: `SELECT MAX(${column}) FROM test`} ); 
    var ret = stmt.execute();
    
    return stmt.getSqlText();
$$ ; 

call my_proc();

It returns:

SELECT MAX(col) FROM test
Sign up to request clarification or add additional context in comments.

2 Comments

Got it, so I must use createStatement in order to achieve what I'm trying to do? I can't call getSqlTest or something equivalent from the execute method?
That's right. snowflake.execute() returns ResultSet object, not Statement object: docs.snowflake.com/en/sql-reference/… And getSqlText() is a method from Statement Object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.