Reputation: 21
What is the difference between table and dictionaries in kdb+? Can you explain why such differences are necessary and what are they good for?
Upvotes: 2
Views: 616
Reputation: 13657
A dictionary can be any arbitrary mapping of keys to values with no restrictions on types, e.g.
q)d:(`abc;1i;.z.D)!(2j;`xyz;.z.P)
q)d[`abc]
2
q)d[2021.03.01]
2021.03.01D06:11:47.519373000
A list of dictionaries which specifically have symbols as keys, have the same keys and have consistent datatypes is promoted to a table. Tables then give you the ability to perform q-sql (select/update/delete) syntax and all of the other advantages that tables bring (persistence, joins).
q)(`abc`def!1 2;`abc`def!3 4)
abc def
-------
1 2
3 4
Dictionaries are still very useful for lookups, mappings, replacements etc
Upvotes: 1
Reputation: 2800
A table is actually a list of dictionaries. E.g.
t:([]sym:`a`b`c;price:1 2 3f)
first t
sym | `a
price| 1f
Upvotes: 2