Hi,
I believe you a referencing to the example here: https://code.kx.com/q4m3/8_Tables/#81-table-definition
8.1.1 Review of Table as Column Dictionary
This says that a table is a flipped column dictionary. “When a dictionarys value items are all same-length lists, it is a column dictionary.” (As per definition here at the end of this page: https://code.kx.com/q/basics/dictsandtables/)
when you select 1 row of a table, you no longer have a column dictionary, but a simple dictionary, which you can’t flip.
q)t:flip name
iq!(Dent
Beeblebrox`Prefect;98 42 126)
q)t
name iq
Dent 98
Beeblebrox 42
Prefect 126
q)t 0
name| `Dent
iq | 98
q)
Now, it’s worth mentioning (and actually important to remember), that a table is actually nothing else than a list of dictionaries. q is smart enough to use the keys of the dictionaries as column names (they obviously need to be the same). You can see this by trying the following:
q)(t 0;t 1)
name iq
Dent 98
Beeblebrox 42
you get a table with two rows (the first two from the original table). Knowing this, you could get a 1 row table doing the following
q)enlist t 0
name iq
Dent 98
One more thing about tables, we know that tables are flipped column dictionaries, but q actually doesn’t flip (reorder the data) but only records that the data should be displayed as a table. You can see this by inspecting the table using 0N!
q)0N!t
+name
iq!(Dent
Beeblebrox`Prefect;98 42 126)
name iq
Dent 98
Beeblebrox 42
Prefect 126
The + in front of the dictionary is k-code for the flip function in q.
q)flip
+:
(In order to keep things simple ignore the : in the above code snippet, it’s k code and it’s best to look at q code for now).
Hope this helps.
Alexander