seeking elegant way to merge a table with null entries only

hello q gods,

let’s say I have two tables


d:( sym:aabc;c1:1 2 3 4;c2:4#0N;c3:0N 10 20 30);

l:([sym:ab]c2:500 600;c3:1000 2000);


q)

q)d

sym c1 c2 c3

------------

a 1

a 2 10

b 3 20

c 4 30

q)

q)

q)l

sym| c2 c3

—| --------

a | 500 1000

b | 600 2000


I want to perform a special left join between these two tables so that instead of the right table overwriting all entries on the left table, it only overwrites if the corresponding entry in the left table is null.


so my expected result is this:


sym c1 c2 c3

---------------

a 1 500 1000

a 2 500 10

b 3 600 20

c 4 30


Not this:

q)d lj l

sym c1 c2 c3

---------------

a 1 500 1000

a 2 500 1000

b 3 600 2000

c 4 30


I can do this using cols[d]xcols 0!((select sym from d)#l)^d

but I strongly believe that a more elegant solution exists and would like to be enlightened..



thank you!

You could use the legacy left join (ljf) but I don’t think this is any better than your current solution since it requires a double join:

(d lj l) ljf 2!d

Terry

How about:

q)(d lj l)^d

sym c1 c2  c3


a   1  500 1000

a   2  500 10

b   3  600 20

c   4      30


From: personal-kdbplus@googlegroups.com <personal-kdbplus@googlegroups.com> on behalf of Terry Lynch <tlyncher@gmail.com>
Sent: 27 May 2016 16:37
To: Kdb+ Personal Developers
Subject: Re: [personal kdb+] seeking elegant way to merge a table with null entries only
 

You could use the legacy left join (ljf) but I don’t think this is any better than your current solution since it requires a double join:

(d lj l) ljf 2!d

Terry