Home › Forums › kdb+ › retrieving values › Re: retrieving values
-
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:
- Tables | Q For Mortals | A textbook forkdb+ and the q programming language – Q for Mortals (kx.com)
- 5. Dictionaries – Q for Mortals (kx.com)
Thanks for posting your query on the portal!
Kind regards,
David