0

I have a table and a function:

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

And I want to apply the function in an update statement on each row and set the result into a new column 'xyz'. How can I do that? This here does not work, as it seems to evaluate the argument as a list:

xyz:update x:fu[name] from table

2 Answers 2

6

You need to use the each-both operator to ensure the function runs on each row separately:

q)update xyz:fu'[name] from table
id xyz
----------------
0  "one_one"
1  "two_two"
2  "three_three"
3  "four_four"
4  "five_five"
Sign up to request clarification or add additional context in comments.

Comments

3

Use each-both: 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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.