Insert a not matching dictionary to a table

https://learninghub.kx.com/forums/topic/insert-a-not-matching-dictionary-to-a-table

Hello,

I would like to append a row to a table with data that is saved as a dictionary. The dictionary might have additional keys when comparing it to the columns in the table so upsert is not possible. I would like to only upsert the values from the dictionary that have corresponding columns in the dictionary. How is this archived?

 

Sample Code

Dictionary td2 and table x where values for a and b should be appended as rows in table x, column c should be empty and value for key d in dictionary should be discarded.

td2:(`a`b`d)!(99;`a;21)

x:([]a:1 2 3;b:`I`J`K;c:10 20 30)
q){k:key y;x upsert enlist (k where k in cols x)#y}[x;td2] 
a b c 
------- 
1 I 10 
2 J 20 
3 K 30 
99 a
q)x upsert td2 
cols x 
a b c 
------- 
1 I 10 
2 J 20 
3 K 30 
99 a