使用翻转内部每个不在KDB中工作

时间:2014-04-25 07:22:25

标签: kdb

在表上使用each,我希望each能够以一行表的形式一次操作一行。但是,它首先被转换为字典:

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

所以显而易见的事情就是使用flip将字典变成表格:

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
嗯 - 那太奇怪了。可以flip一本字典吗?出了什么问题?

1 个答案:

答案 0 :(得分:7)

请记住,该表是字典列表。

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/

每个字典的值都是原子,而不是列表。所以你不能flip将字典放到表格中,你必须确保这些值是列表。

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