2021.02.22 10:20 AM
2021.02.22 10:23 AM
q),''/[(a;b;c)]
key1| val
----| -----
a | 1 4 7
b | 2 5 8
c | 3 6 9
2021.02.22 10:27 AM
2021.02.22 11:10 AM
2021.02.22 11:42 AM - last edited a month ago
A keyed table is a dictionary mapping between a table of keys and a table of values, so a simple join will have upsert semantics.
q)a,b,c
key1| val
----| ---
a | 7
b | 8
c | 9
We may apply the join operation between the values of two dictionaries using each. We might ordinarily expect this to work, like:
q)(`a`b`c!1 2 3),'(`a`b`c!4 5 6)
a| 1 4
b| 2 5
c| 3 6
However, the values of a keyed table are the rows of the value table, which are themselves dictionaries (remember a table is a list of dictionaries), so we still see upsert semantics.
q)a,'b,'c
key1| val
----| ---
a | 7
b | 8
c | 9
The key insight is that we need to further map the join-each operation onto the values of these row dictionaries:
q)a,''b,''c
key1| val
----| -----
a | 1 4 7
b | 2 5 8
c | 3 6 9
And with this, we can use over to apply this join-each-each operation to a list of keyed tables.
q),''/[(a;b;c)]
key1| val
----| -----
a | 1 4 7
b | 2 5 8
c | 3 6 9
2021.02.22 12:43 PM
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.