Kasia Ka
Kasia Ka

Reputation: 41

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.

Upvotes: 0

Views: 101

Answers (2)

rianoc
rianoc

Reputation: 3786

Set up sample:

t:([] person:`a`b;personData:(`name`age`address!(`jo;7;"neverland");`name`age`DOB!(`mary;42;1982.01.05)))
t
person personData
--------------------------------------------
a      `name`age`address!(`jo;7;"neverland")
b      `name`age`DOB!(`mary;42;1982.01.05)

Update:

update personData:{x[`tel]:y;x}'[personData;1234 5678] from t
person personData
-----------------------------------------------------
a      `name`age`address`tel!(`jo;7;"neverland";1234)
b      `name`age`DOB`tel!(`mary;42;1982.01.05;5678)

Or using a . amend:

update personData:.[personData;(::;`tel);:;1234 5678] from t
person personData
-----------------------------------------------------
a      `name`age`address`tel!(`jo;7;"neverland";1234)
b      `name`age`DOB`tel!(`mary;42;1982.01.05;5678)

Upvotes: 0

terrylynch
terrylynch

Reputation: 13657

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)

Upvotes: 1

Related Questions