如何在更新语句中使用每行的值设置函数参数?

时间:2018-09-20 17:25:11

标签: kdb

我有一张桌子和一个函数:

table:([] id:til 5; name:("one";"two";"three";"four";"five"))
fu:{[x] x,"_",x}

我想在每行的更新语句中应用该函数,并将结果设置到新列“ xyz”中。我怎样才能做到这一点? 这似乎不起作用,因为它似乎将参数作为列表求值:

xyz:update x:fu[name] from table

2 个答案:

答案 0 :(得分:6)

您需要使用each-both运算符,以确保函数分别在每一行上运行:

q)update xyz:fu'[name] from table
id xyz
----------------
0  "one_one"
1  "two_two"
2  "three_three"
3  "four_four"
4  "five_five"

答案 1 :(得分:3)

同时使用:https://code.kx.com/q/ref/adverbs/#each-both

q)update xyz:fu'[name]from table
id name
----------------
0  "one_one"
1  "two_two"
2  "three_three"
3  "four_four"
4  "five_five"