Search code examples
kdb

Getting type error while adding 2 dictionaries in KDB


I am able to add and assign the second dictionary (s i) to the one with (d t)

d1:`d`t!(.z.d ;.z.t)
d1,:`s`i!`VOD`L
d1

However the other way round does not work, I am getting type error :

d2:`s`i!`VOD`L
d2,:`d`t!(.z.d ;.z.t)
d2

Solution

  • In the first case, (d t) is making a heterogenous dictionary :

    q)d1:`d`t!(.z.d ;.z.t)
    q)type value d1
    0h
    

    now if you add and assign any homogeneous or heterogenous dictionary, it will work.

    while in another case the first dictionary created is homogeneous , and it is throwing error when you add & assign a heterogenous dictionary (or homogeneous dictionary of another type for that matter )

    q)d2:`s`i!`VOD`L
    q)type value d2
    11h
    q)type value `d`t!(.z.d ;.z.t)
    

    To solve this issue , you should only add the dictionary and then assign it.

    q)d2:`s`i!`VOD`L
    q)d2:d2, `d`t!(.z.d ;.z.t)
    q)d2
    s| `VOD
    i| `L
    d| 2018.03.25
    t| 09:59:17.109