Kdb how to remove a string key from a dictionary

I am having a hard time removing an entry from the KDB dictionary. The keys and values ​​are strings.

IN

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

      

Does not work

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

      

Thank you, Eugene

+3


source to share


2 answers


Since the type of "list of keys" in your dictionary is 0h (mixed list or list of list)

     q) type ("k1";"k2";"ABC")
     q) 0h

      

and your only key type is 10h (string)

     q)  type "k1"
     q) 10h

      



This is why kdb gives you a type error when matching.
Link: http://code.kx.com/q4m3/5_Dictionaries/

It says: "The left operand of the delete is the dictionary (target), and the right operand is the key value, the type of which matches the type of the target."

You can use the following to delete an entry:

      q)   (k@where not (k:key l2) like "k1")#l2

Key Value
k2  v2
ABC BLA BLA

      

+3


source


I think you should use enlist

to remove a string key from a dictionary:

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

      



_

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

"k1".

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

+4


source







All Articles