function return a table in kdb/q
function return a table in kdb/q I'm new in kdb/q and I'm not familiar with kdbq function, hope someone can help me. Here is the question: I have a simple q function declared as the following: func:{[x;y] x+y} And {[x;y] x+y}[3;4] gives me the answer 7 . Everything works perfectly. {[x;y] x+y}[3;4] 7 If I have a table t with two columns such as: t _x _y -------- 3 4 2 5 6 2 ... Could I have a function in q such that compute x+y for each row of table t ? And my expected return would be something like: x+y t res --- 7 7 8 ... Thanks so much! 2 Answers 2 You can just pass the column names as parameters to the function: q)tab:(x:1 2 3;y:4 5 6) q)func:{[x;y] x+y} q) q)select res:func[x;y]from tab res --- 5 7 9 Alternatively you could use functional form to turn that query into a function: q){?[x;();0b;enlist[`res]!enlist(`func;y;z)]}[tab;`x;`y] res --- 5 7 9 ...
