Shekhar
Shekhar

Reputation: 102

Q/Kdb: Combining two columns to create a new column as list

I needed a help in creating a new column as a list using two pre-existing column

CcyPair, Amount1, Amount2 
USDJPY   1666     2400
EURUSD   2344     3000

I want new output as

CcyPair, Amount1, Amount2, NewAmount
USDJPY   1666     2400     1666 2400
EURUSD   2344     3000     2344 3000

I tried doing Select CcyPair,Amount1,Amount2,NewAmount:(Amount1;Amount2) from table

but getting length error

Any ideas how this can be resolved. Thanks

Upvotes: 1

Views: 3836

Answers (2)

Josh
Josh

Reputation: 36

I think an update statement is what you want here.

Try:

update NewAmount:flip(Amount1;Amount2) from table

You can read more about update statements here: https://code.kx.com/q4m3/9_Queries_q-sql/#95-the-update-template

Upvotes: 2

Anton Dovzhenko
Anton Dovzhenko

Reputation: 2569

You should use ,' operator, which works like "pairwise" append. Please, note, that in update or select statements it must be surrounded with brackets, otherwise comma will be misinterpreted by q-slq

t: ([]CcyPair: `USDJPY`EURUSD; Amount1: 1666 2344; Amount2: 2400 3000);
t: update NewAmount: (Amount1,'Amount2) from t;
t

Upvotes: 3

Related Questions