kdb+q

KDB Update dictionary column from a table


I have a table called details which has 2 columns, person(s) and personData(dict) the personData is basically a dictionary which holds all person information.

If I want to add an additional entry into the dictionary how would I go about doing that? I want the personData to be updated to hold telNO.

telNos:1234 9594 (is a list of numbers) when I run:

(flip details`personData),enlist[`telNo]!(enlist telNos)

it works, but this is me taking the dictionary apart, whereas I need to update the entire table at once.


Solution

  • Assuming

    q)show t:([]person:`a`b;personData:(`name`age!(`aa;1);`name`age!(`bb;2)))
    person personData
    ------------------------
    a      `name`age!(`aa;1)
    b      `name`age!(`bb;2)
    

    You can update one record with

    q)update @[;`telNo;:;111]personData from t where person=`a
    person personData
    ----------------------------------
    a      `name`age`telNo!(`aa;1;111)
    b      `name`age!(`bb;2)
    

    or all of them with

    q)update @'[;`telNo;:;111 222]personData from t
    person personData
    ----------------------------------
    a      `name`age`telNo!(`aa;1;111)
    b      `name`age`telNo!(`bb;2;222)