KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ retrieving values

  • retrieving values

    Posted by Laura on October 12, 2021 at 12:00 am

    I have a basic question:

    a[‘name] vs b[val;’name]

    Do I understand the first is a dictionary and I get the value that corresponds to a key “name”? But what data structure is the second? Is that a list? I am reading the code and trying to make sense of what I see.

     

    Laura replied 8 months ago 2 Members · 1 Reply
  • 1 Reply
  • davidcrossey

    Member
    October 13, 2021 at 12:00 am

    Hi MEdan,

    It depends if your variable is a dictionary or a table as this flips the indexes:

    • dictionary = d[key;index]
    • table = t[index;key]

    For example:

     

    q)d:`name`iq!(`Dent`Beeblebrox`Prefect;98 42 126) 
    q)d 
    name| Dent Beeblebrox Prefect 
    iq  | 98 42 126 
    q)t:flip d 
    q)t 
    name       iq 
    -------------- 
    Dent       98 
    Beeblebrox 42 
    Prefect    126
    
    q)d[;2] 
    name| `Prefect 
    iq  | 126 
    
    q)d[`name;] 
    `Dent`Beeblebrox`Prefect 
    q)d[`name;2] 
    `Prefect 
    q)t[2;] 
    name| `Prefect 
    iq  | 126 
    
    q)t[;`name] 
    `Dent`Beeblebrox`Prefect 
    q)t[2;`name] 
    `Prefect

     

    Passing only the symbol to either dictionary or table will return the associated values key/column:

     

    q)d `iq 
    98 42 126 
    q)t `iq 
    98 42 126

     

    Further reading:

    Thanks for posting your query on the portal!

    Kind regards,

    David

Log in to reply.