سؤال

Using each on a table, I was expecting each to operate on one row at a time in the form of a one-row table. However, it is being converted to a dictionary first:

q) t:flip `a`b!(enlist 1;enlist 2);
q) {type x} each t
enlist 99h  / dictionary

So the obvious thing to do is just use flip to make the dictionary into a table:

q) {type flip x} each t
An error occurred during execution of the query.
The server sent the response:
rank
Studio Hint: Possibly this error refers to invalid rank or valence

Hmm - that's wierd. Can't flip a dictionary?? What's going wrong?

هل كانت مفيدة؟

المحلول

Remember that table is a list of dictionary.

q)show each ([]a:1 2 3;b:4 5 6);
a| 1
b| 4
a| 2
b| 5
a| 3
b| 6

http://code.kx.com/q4m3/8_Tables/

The values of each dictionary are atoms, not lists. So you can't flip a dictionary into a table that way, you have to make sure the values are lists.

q)enlist each ([]a:1 2 3;b:4 5 6)
+`a`b!(,1;,4)
+`a`b!(,2;,5)
+`a`b!(,3;,6)
q)type each enlist each ([]a:1 2 3;b:4 5 6)
98 98 98h
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top