DankyKang
DankyKang

Reputation: 25

append item to dictionary list, kdb

I have a dictionary

q).test.dict:(`test1;`test2)!(1i;2i)
q).test.dict
test1| 1
test2| 2

and I need to append an item to one of the dictionary lists to get the following result:

q).test.dict
test1| 1
test2| 2 4i

However I am having trouble assigning to that dictionary list.

I have tried the following:

q).test.dict[`test2]:.test.dict[`test2],4i
'type
  [0]  .test.dict[`test2]:.test.dict[`test2],4i

And have tried other methods of assignment which also result in a type error.

I feel like im missing something quiet obvious here but cant seem to put my finger on it.

Upvotes: 0

Views: 1488

Answers (2)

user12704155
user12704155

Reputation:

If you instead define your dictionary like this

.test.dict:(`test1;`test2)!(enlist 1i;enlist 2i)

It will work. The problem is, the value of your dictionary is a list of integers, not a list of lists of integers.

Upvotes: 1

terrylynch
terrylynch

Reputation: 13572

The issue is that you've initiated/defined the dictionary to have a uniform value (integer atoms) and so kdb expects/enforces the values to remain integer atoms. You can avoid this by creating a default entry (with say generic null ::) to force the value to be a mixed list. Then you can append

.test.dict:(`;`test1;`test2)!(::;1i;2i)

Upvotes: 1

Related Questions