key-ed table
key-ed table is not a table, it is a dictionary, demonstrating this:q)v:flip `name`iq!(`Dent`Beeblebrox`Prefect;98 42 126)
q)k:flip (enlist `eid)!enlist 1001 1002 1003
q)kt:k!v
as a result, you can access the row using dictionary key lookup:q)kt[(enlist `eid)!enlist 1002] /or
q)kt ([] eid:1001 1002) /or
q)([] eid:1001 1002)#kt / which is drawing
reverse look up as with a dictionaryq)kts:([eid:1001 1002 1003] name:`Dent`Beeblebrox`Prefect)
q)kts?([] name:`Prefect`Dent)
/ introspecting a key'ed table
q)key kt / which gets the key columns
q)value kt
q)keys kt / which gets key names
q)cols kt / which gets column names from bot key table and value table
several operations around keys of a key'ed table/add a key with a column of a name
q)`eid xkey kt
q)() xkey kt
/add a key with a column at a position
q)1!kt
q)0!kt
gotcha: If xkey is applied with a column that does not contain unique values, the result is not a error but rather a keyed table that does not have a true primary key.compound key'ed tableq)ktc:([lname:`Dent`Beeblebrox`Prefect;
fname:`Arthur`Zaphod`Ford]; iq:98 42 126)
q)ktc[`lname`fname!`Beeblebrox`Zaphod]
q)ktc[`Dent`Arthur]
q)ktc (`Dent`Arthur;`Prefect`Ford)
q)K:([] lname:`Dent`Prefect; fname:`Arthur`Ford)
q)K#ktc