bigO6377
bigO6377

Reputation: 1274

KDB concatenating strings inside select/exec statements

I have a table T with column Sym:`IBM`MSFT`GOOG... Want the easiest way to create new column of the form newColumn: "IBM_Buy","MSFT_Buy","GOOG_Buy",...

The following does NOT seem to do the trick: select ((string Sym),"_Buy") from T

Upvotes: 6

Views: 13896

Answers (3)

Rahul
Rahul

Reputation: 3969

t:([]sym:`IBM`MSFT`GOOG)

update newsym:(string sym) cross enlist "_Buy" from t

or easy way (Dictionary Format)

t[`newsym] :
(string t[`sym]) cross enlist "_Buy"

Upvotes: 1

G. A.
G. A.

Reputation: 25

You may use each-both (') function with anonymous function in select statement:

select {x, "_Buy"}'[Sym] from T

Upvotes: 1

user1895961
user1895961

Reputation: 1186

You need to use each-left (\:). Think of it as concatenating "_Buy" to each item on a list.

select (string[Sym],\:"_Buy") from T

Upvotes: 9

Related Questions