2022.04.22 04:16 AM
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)
2022.04.22 06:25 AM
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
2022.04.25 03:22 AM
q)x upsert td2 cols x
a b c
-------
1 I 10
2 J 20
3 K 30
99 a
2022.04.22 06:25 AM
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
2022.04.25 03:22 AM
q)x upsert td2 cols x
a b c
-------
1 I 10
2 J 20
3 K 30
99 a
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.