DolphinDB:在SQL语句中使用动态函数时出错

问题描述 投票:0回答:1

以下是我的脚本:

sym = `C`MS`MS`MS`IBM`IBM`C`C`C$SYMBOL
price= 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29
qty = 2200 1900 2100 3200 6800 5400 1300 2500 8800
timestamp = [09:34:07,09:36:42,09:36:51,09:36:59,09:32:47,09:35:26,09:34:16,09:34:26,09:38:12]
t1 = table(timestamp, sym, qty, price)

//select *, cumsum(qty) from t1 context by sym
//select *, cumsum2(qty) from t1 context by sym

def demo(t, dynamicFunc) {
        return select select *, dynamicFunc(qty) from t context by sym
}

demo(t1, cumsum)

语句

return select *, dynamicFunc(qty) as dynamicFunc_qty from t context by sym
引发错误:
Not allowed to use dynamic function in sql statement

“动态函数”

dynamicFunc
是作为参数传递的,不能在SQL语句中执行。如何解决 DolphinDB 中的此错误?

sql dynamic-programming dolphindb
1个回答
0
投票

DolphinDB 服务器 3.00 支持在 SQL 语句中使用动态函数,但服务器 2.00 不支持。您可以使用

call
函数解决此问题,如下所示:

def demo(t, dynamicFunc) {
        return select *, call(dynamicFunc, qty) from t11 context by sym
}
© www.soinside.com 2019 - 2024. All rights reserved.