我在DolphinDB database GUI中定义了下面函数:
def myfunc(){
t1 = table(1..100 as id)
re = parseExpr("select * from t1 where id in (1..10)").eval()
return re
}
myfunc()
执行后报错:
myfunc() => myfunc: re = ::evaluate(parseExpr("select * from t1 where id in (1..10)")) => Can't find the object with name t1。
我把它改成如下:
def myfunc(){
t1 = table(1..100 as id)
re = select * from objByName("t1")
return re
}
myfunc()
执行后还是报错:
myfunc() => myfunc: re = select * from objByName("t1") => Can't find the object with name t1。
请问这是为什么?
在用户手册对objByName有如下说明:
简单的说,objByName优先搜索节点中定义的共享变量,然后再去搜索当前会话中定义的变量,不会去搜索函数内部定义的的局部变量。parseExpr中的变量搜索同objByName。
要解决上面的代码的问题,可以使用sql函数动态生成: