Search code examples
kdb

KDB - Why does upsert work when insert does not


I am trying to manipulate the upd function in a KDB tickerplant so that it can accept a table as the data argument.

When trying to insert locally, insert does not seem to like being passed the data from the table but will handle a list of lists fine when passed from the feedhandler. Why is this?

tbl1:([] sym:`symbol$(); price:`int$(); vol:`long$())
tbl2:([] sym:3?`3;price:3?10i;vol:3?100j)
insert[tbl1;(value each tbl2)]
'type
upd:{[t;x] upsert[t;x]}
upd[`tbl1;(value each tbl2)]
`tbl1

Solution

  • There are two issues with your example above

    1. insert requires the left argument to be a symbol atom
    2. the right argument needs align with the columns of the table
    q)insert[`tbl1;value flip tbl2];tbl1
    sym price vol
    -------------
    lhk 8     49
    mga 1     82
    mio 7     40
    

    upsert is more flexible