我正在使用Snowflake存储过程,该过程将采用从一个数据库更改为另一个数据库的视图。我正在尝试
var sqlCommand = `
SELECT a.OBJECT_NAME, a.OBJECT_SCHEMA, a.OBJECT_TYPE, d.VIEW_DEFINITION
FROM VIEW_OBJECT_LIST a
INNER JOIN DB_DEV.INFORMATION_SCHEMA.VIEWS d ON a.OBJECT_NAME = d.TABLE_NAME AND a.OBJECT_SCHEMA = d.TABLE_SCHEMA
INNER JOIN DB_QA.INFORMATION_SCHEMA.VIEWS q ON a.OBJECT_NAME = q.TABLE_NAME AND a.OBJECT_SCHEMA = q.TABLE_SCHEMA AND d.VIEW_DEFINITION != q.VIEW_DEFINITION;`;
var viewList = snowflake.createStatement({ sqlText: sqlCommand}).execute();
while(viewList.next()){
var sql = viewList.VIEW_DEFINITION;
var sql = 'USE DB_QA; ' || sql;
snowflake.createStatement({ sqlText: sql }).execute();
}
但收到错误消息
Unsupported statement type 'USE'. At Statement.execute
Snowflake存储过程中是否有一种方法可以在调用Snowflake API的过程中运行USE语句?
答案 0 :(得分:1)
我相信唯一的问题是您尚未定义DB_QA
语句中的USE
。我假设它是数据库的名称,所以您只需要将该行修改为:
var sql = 'USE DATABASE DB_QA; ' || sql
我不确定snowflake.createStatement
是否允许传递多语句查询。您必须让我知道是否可行。
答案 1 :(得分:0)
在创建此存储过程时使用的执行权限是什么? 如果在创建过程语句中使用“ EXECUTE AS OWNER”,则可能无法使用以下语句以外的语句:->
Restrictions on SQL Statements
Although caller’s rights stored procedures can execute any SQL statement that the caller has sufficient privileges to execute outside a stored procedure, owner’s rights stored procedures can call only a subset of SQL statements.
The following SQL statements can be called from inside an owner’s rights stored procedure:
SELECT.
DML.
DDL. (See above for restrictions on the ALTER USER statement.)
GRANT/REVOKE.
Variable assignment.
DESCRIBE and SHOW. (See limitations documented above.)
Other SQL statements cannot be called from inside an owner’s rights stored procedure.
请尝试使用“ EXECUTE AS CALLER”创建相同的过程,这将允许雪花本机sql命令,例如LIST,USE DATABASE,RM等。