Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kdb how to remove string key from dictionary

Tags:

kdb+

I am having difficulty removing an entry from KDB dictionary. Keys and values are strings.

Working

q)l3:`a`b`c!1 2 3
q)`a _l3
b| 2
c| 3

Not working

q)l2:("k1";"k2";"ABC")!("v1";"v2";"BLA BLA")
q)"k1" _l2
'type

Thanks, Eugene

like image 301
Vortex Avatar asked Dec 09 '25 07:12

Vortex


1 Answers

I think you should use enlist to drop the string key from dictionary:

q)enlist["k1"]_("k1";"k2";"ABC")!("v1";"v2";"BLA BLA")
"k2" | "v2"
"ABC"| "BLA BLA"

_(drop) takes left input as list of elements of the dictionary key (with exception when it comes to symbol key). Try to imagine that in your case, "k1" is an 'atom' and to create a singleton list, you can just enlist "k1".

Reference: http://code.kx.com/q/ref/lists/#_-cut

like image 87
WooiKent Lee Avatar answered Dec 12 '25 19:12

WooiKent Lee