在此链接中,有一个关于如何包含动态参数的示例.d
,在KDB选择查询中:
h: hopen`:myhost01:8012 // open connection
d: 2016.02.15 // define date var
symList: `GBPUSD`EURUSD
h raze "select from MarketDepth where date=", string d, ", sym in `GBPUSD`EURUSD" // run query with parameter d
Run Code Online (Sandbox Code Playgroud)
这d
是类型date
,并且易于字符串连接以生成动态查询.
如果我想symList
通过转换为字符串添加为动态参数:
raze "select from MarketDepth where date=", string d, ", sym in ", string symList
Run Code Online (Sandbox Code Playgroud)
连接的字符串变为:select from MarketDepth where date=2016.02.15, sym in GBPUSDEURUSD
,换句话说,字符串连接会丢失反引号,因此查询不会运行.我怎么解决这个问题?
pS:我知道功能查询但是在失败2小时后,我已经放弃了.
无需功能选择.
q)MarketDepth:([] date:9#2016.02.15; sym:9#`A`B)
q)d:2016.02.15
q)symList:`B
q)h ({[dt;sl] select from MarketDepth where date=dt,sym in sl}; d; symList)
date sym
--------------
2016.02.15 B
2016.02.15 B
2016.02.15 B
2016.02.15 B
Run Code Online (Sandbox Code Playgroud)