kdb+q

adding to a column which is list of symbols and finding right datatype from meta information


I have a table which has 2 columns whose elements are list of symbols. I want to modify one of these columns to append a symbol to existing list of symbols, how can i do it ?

/Table with 2 columns containing list of symbols

tab:([] a:`A`B ;colList1:(`x`y`z;`p`q`r);colList2:(`x`y`z;`p`q`r));

/Gives me a list of symbols in colList2 but not in colList1, I need this for my task
 (exec colList1 from tab ) except'(exec colList2 from tab );

/Gives me a list of symbols in colList2 but not in colList1, I need this for my task
(exec colList2 from tab ) except'(exec colList1 from tab );

update missingincol2:(exec colList1 from tab ) except'(exec colList2 from tab ), missingincol1: (exec colList2 from tab ) except'(exec colList1 from tab ) from tab;

update colList1:colList1\:,`ooo from tab / This does not work as intended, I thought for each colList in it will join `ooo to it. But it looks like it create a new column x .

Moreover, when I do meta on a kdb table some of the columns which are list of list gets showed datatype as empty value. If there is a missing column which i want to add in my tickerplant log, how do i do this for a column which is list of list? Note that i do need to modify tp logs and so do not want to use dbmaint script etc. which would make changes directly on hdb level as I replay logs for my task.


Solution

  • Your final update statement should read:

    q)update colList1:(colList1,\:`ooo)from tab
    a colList1  colList2
    --------------------
    A x y z ooo x y z
    B p q r ooo p q r
    

    Commas indicate a new phrase in the statement so you need brackets to make it explicit that this indicates the join operator. Also the each-left (\:) iterator should be to the right of the operator you're modifying.