How to bind a variable in a snowflake create schema

Viewed 118

I have a simple sql code I want to execute in my stored procedure
I am trying to bind the name of a schema but I am struggling to make it work
Below is my code

CREATE OR REPLACE PROCEDURE DATABASE.SCHEMA."CREATE_SCHEMA"("SCHNAME" VARCHAR(16777216))
RETURNS VARCHAR(16777216)
LANGUAGE JAVASCRIPT
COMMENT='Creates roles for new schemas'
EXECUTE AS CALLER
AS 
$$

    var sqlCode = "CREATE SCHEMA ?";  
    var statement = snowflake.createStatement({sqlText:sqlCode,binds:[SCHNAME]});  
    var result_set = statement.execute(); 

$$

When I bind variables in a select query for example, it works but I don't know how to do it
in a statement above like CREATE
Any help would be greatly appreciated.

1 Answers

Keep in mind that binds are variables. When you use variables in Snowflake for object names, you need to use them inside the IDENTIFIER() function. The same rule applies for the SP:

var sqlCode = "CREATE SCHEMA identifier(?)";  
Related