Store column as string in kdb

I have a table with numerous columns. I am trying to take data from one of the columns and return it as a string.

For example, if I had:

A B C
1 2 3
4 5 6
7 8 9

      

I would like to take column B and store 258 as a string. How should I do it?

+3


source to share


2 answers


Like this?

q)raze exec string B from ([] A:1 4 7;B:2 5 8;C:3 6 9)
"258"

      



Or are you trying to change the type of a column in a table?

q)update string B from ([] A:1 4 7;B:2 5 8;C:3 6 9)
A B    C
--------
1 ,"2" 3
4 ,"5" 6
7 ,"8" 9

      

+3


source


If all your entries are single digits, all you have to do is

.Q.n t.B

      

Taking your data as an example,

q)show t:([] A:1 4 7;B:2 5 8;C:3 6 9)
A B C
-----
1 2 3
4 5 6
7 8 9
q).Q.n t.B
"258"

      



Note that .Q.n

this is just a string containing 10 digits:

q).Q.n
"0123456789"

      

If you want to store a row in a table, just use update

:

q)update .Q.n B from `t
`t
q)t.B
"258"

      

+2


source







All Articles