Reputation: 43
I would like to join (concatenate) 2 or more, KDB tables which have repeating columns:
d1:`a`b`c!(1 2 3;4 5 6;7 8 9)
d2:`a`b`c`a!(10 20 30;40 50 60;70 80 90;100 110 120)
t1: flip d1
a b c
-----
1 4 7
2 5 8
3 6 9
t2: flip d2
a b c a
------------
10 40 70 100
20 50 80 110
30 60 90 120
I am trying to concatenate the 2 tables, with nils where a table does not have a value, something like the following:
a b c a
------------
1 4 7
2 5 8
3 6 9
10 40 70 100
20 50 80 110
30 60 90 120
t1 uj t2
yeilds (only has as many columns as t1 has defined):
a b c
--------
1 4 7
2 5 8
3 6 9
10 40 70
20 50 80
30 60 90
t2 uj t1
(repeats the entries from t1 where they are not available)
a b c a
------------
10 40 70 100
20 50 80 110
30 60 90 120
1 4 7 1
2 5 8 2
3 6 9 3
Is this possible? or would I need to pre-define a table which can accommodate all possible columns? Any advice would be appreciated.
Regards Clifford
Upvotes: 2
Views: 3173
Reputation: 3969
Your second table has 2 columns with same name ('a') and that's giving the issue. rename it and uj will work.
q) t1:flip `a`b`c!(1 2 3;4 5 6;7 8 9)
q) t2:flip `a`b`c`d!(10 20 30;40 50 60;70 80 90;100 110 120)
q) t1 uj t2
a b c d
1 4 7
2 5 8
3 6 9
10 40 70 100
20 50 80 110
30 60 90 120
Upvotes: 3