0

How to get an additional column of type string using ??

I tried this:

t:([]c1:`a`b`c;c2:1 2 3)
?[t;();0b;`c1`c2`c3!(`c1;`c2;10)]           / ok
?[t;();0b;`c1`c2`c3!(`c1;`c2;enlist(`abc))] / ok
?[t;();0b;`c1`c2`c3!(`c1;`c2;"10")]         / 'length
?[t;();0b;`c1`c2`c3!(`c1;`c2;enlist("10"))] / 'length

but got 'length error.

egor7
  • 4,678
  • 7
  • 31
  • 55

1 Answers1

2

Your first case works because an atom will automatically expand to the required length. For a compound column you'll need to explicitly generate the correct length as follows

q)select c1,c2,c3:`abc,c4:10,c5:count[i]#enlist"abc" from t
c1 c2 c3  c4 c5
------------------
a  1  abc 10 "abc"
b  2  abc 10 "abc"
c  3  abc 10 "abc"

// in functional form
q)?[t;();0b;`c1`c2`c3!(`c1;`c2;(#;(count;`i);(enlist;"abc")))]
c1 c2 c3
-----------
a  1  "abc"
b  2  "abc"
c  3  "abc"

Jason

jasonfealy
  • 1,081
  • 3
  • 5
  • Thank you Jason! Yes, the same problem I've faced recently even with non-functional select, and your answer helped me twice! :) – egor7 Sep 11 '20 at 10:02