【发布时间】:2020-04-26 16:14:43
【问题描述】:
我在 Snowflake 上运行此存储过程,但收到此错误“”存储过程 READ_RESULT_SET 中的执行错误:SQL 编译错误:谓词 [?] 的无效数据类型 [VARCHAR(5)] 在 Statement.execute 行12 位置 19""
表信息: Table1.header = [Segment, Condition], Table1.column1 = [aaa,bbb,ccc,ddd], Table1.column2 = [A=1, B=1, C=1, D=1]
Table2.header = [A, B, C, D], Table2.column1 = [1,0,0,0], Table2.column2 = [1,0,1,0], Table2.column3 = [ 0,0,0,0], Table2.column4 = [0,1,0,0]
我正在尝试从 Table1 中获取 column2 并在第二个查询中将它们作为我的条件运行。如果我复制相同的条件并将它们手动添加到查询中,它会完美运行。
create or replace procedure read_result_set()
returns float not null
language javascript
as
$$
var my_sql_command = "select * from TABLE1";
var statement1 = snowflake.createStatement( {sqlText: my_sql_command} );
var result_set1 = statement1.execute();
// Loop through the results, processing one row at a time...
var result = 0
while (result_set1.next()) {
var condition = result_set1.getColumnValue(2);
stmt = snowflake.createStatement( { sqlText: "select * from TABLE2 where ?;",binds:[condition] } ); ###THE PROBLEM IS IN THIS LINE
//stmt = snowflake.createStatement( { sqlText: "select * from TABLE2 where A = 1;" } ); ####If I try this line instead, it works perfect
res = stmt.execute();
while (res.next()) {
var one = res.getColumnValue(1);
var two = res.getColumnValue(2);
var three = res.getColumnValue(3);
var four = res.getColumnValue(4);
stmt2 = snowflake.createStatement( { sqlText: "INSERT INTO RESULT VALUES (?, ?, ?, ?);", binds:[one, two, three, four, one] } );
res2 = stmt2.execute();
}
//res.next();
//returned_value = res.getColumnValue(1);
}
return 0.0; // Replace with something more useful.
$$
;
call READ_RESULT_SET()
【问题讨论】:
标签: stored-procedures snowflake-cloud-data-platform