Search code examples
kdbq-lang

kdb+ : concatenate table elements into a third column


I have this:

a     b     c
"aa"  "bb"  "cc"
"aaa" "bbb" "ccc"

I want to end up with -,|,/,\ in between or any other third string:

a     b     c     ab
"aa"  "bb"  "cc"  "aa-bb"
"aaa" "bbb" "ccc" ""aaa-bbb"

for example


Solution

  • q)d:flip `a`b`c!flip 2 3#'\:"abc"
    q)select ab:sv'["-";flip (a;b)] from d
    ab
    ---------
    "aa-bb"
    "aaa-bbb"
    q)select  "-"0:(a;b) from d
    b
    ---------
    "aa-bb"
    "aaa-bbb"