Search code examples
kdbq-lang

KDB appending tables with different columns


I have two tables, that have some columns in common and some columns that the other table does not have.

atab:flip `items`sales`prices`athing!(`anut`abolt`acam`acog;6 8 0 3;10 20 15 20; 50.2 32.6 1.18 -3.9)

btab:flip `items`sales`prices`bthing!(`bnut`bbolt`bcam`bcog;6 8 0 3;10 20 15 20; 1 0 0 1)

and I am trying to combine them such that the column set it the union of the two tables, so in my case, columns would be items, sales, prices, athing, bthing and where the initial table doesnt have a corresponding column, gets filled with some n/a value

This here fails for

atab upsert btab

the error

ERROR:mismatch

Is there a way that I can (easily) do that?


Solution

  • q)atab uj btab
    items sales prices athing bthing
    --------------------------------
    anut  6     10     50.2
    abolt 8     20     32.6
    acam  0     15     1.18  
    acog  3     20     -3.9
    bnut  6     10            1
    bbolt 8     20            0
    bcam  0     15            0
    bcog  3     20            1
    

    http://code.kx.com/q/ref/joins/#uj-ujf-union-join