Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KDB: how do I insert/upsert rows from one table to another

Tags:

kdb+

k1:([a:("ff"; "yy"; "zz");z:("tt"; "yy"; "hh")] b:("33"; "44"; "55"); c:("66"; "77"; "88"))


k2:([z:()] a:(); b:(); c:(); m:(); i:())

k1 and k2 are keyed tables. k2 has all the columns of k1 and more.

How do I perform a conditional upsert from k1 to k2. Basically, what is the corresponding working statement of the one below:

`k2 upsert select k1 where a="ff"
like image 958
pom Avatar asked Dec 06 '25 04:12

pom


1 Answers

I think this will solve your issue:

k2 uj `z xkey select from k1 where a like "ff"

the xkey will maintain the key on k2 while the uj will maintain all of the columns, including those without values in k1.

In this example this would return:

z   | a    b    c    m i
----| ------------------
"tt"| "ff" "33" "66"
like image 186
Joe Griffiths Avatar answered Dec 09 '25 20:12

Joe Griffiths