2012-09-19 119 views
4

查看所有文檔。爲什麼這不起作用?加載的sp.q示例文件在KDB分發中給出。我無法弄清楚這個聲明有什麼問題。kdb更新語句

q) \l sp.q 
q)trade 
date  sym time   price size 
----------------------------------------- 
2007.07.23 a 04:48:52.665 73.53941 1000 
2007.07.23 a 04:48:52.675 81.73358 600 
2007.07.23 a 04:48:52.725 78.79526 900 
2007.07.23 a 04:48:52.735 79.59502 600 
2007.07.23 b 04:48:52.655 84.59765 200 
2007.07.23 b 04:48:52.685 98.36199 500 
2007.07.23 b 04:48:52.705 97.49875 700 
2007.07.23 c 04:48:52.645 61.48308 900 
2007.07.23 c 04:48:52.695 61.53192 700 
2007.07.23 c 04:48:52.715 71.95405 200 

q)trade:update size:300 from trade where sym=`c,price>71 
'par 
q)trade 
date  sym time   price size 
----------------------------------------- 
2007.07.23 a 04:48:52.665 73.53941 1000 
2007.07.23 a 04:48:52.675 81.73358 600 
2007.07.23 a 04:48:52.725 78.79526 900 
2007.07.23 a 04:48:52.735 79.59502 600 
2007.07.23 b 04:48:52.655 84.59765 200 
2007.07.23 b 04:48:52.685 98.36199 500 
2007.07.23 b 04:48:52.705 97.49875 700 
2007.07.23 c 04:48:52.645 61.48308 900 
2007.07.23 c 04:48:52.695 61.53192 700 
2007.07.23 c 04:48:52.715 71.95405 200 

回答

2

表格按日期分區。您需要指定一個日期來執行查詢,例如

trade:update size:300 from trade where sym=`c,price>71, date within (<d1>;<d2>) 
+0

我可能是錯的,但他不應該[使用前'trade'反引號,而不是僅僅'trade'(HTTP:// WWW .thalesians.com/finance/index.php/KnowledgeBase/Databases/Kdb#Update_tables),所以他的表會被修改而不是被複制? – vladr

+0

不,他在幹什麼,雖然這也會起作用: '更新大小:300來自\'交易其中sym = \ c,價格> 71,日期在(; )' – mollmerx

+0

您無法更新所有分區表,有或沒有反引號或日期條件。 –

4

trade是一個分區表,這就是爲什麼這是失敗。你究竟想要做什麼?如果你想在內存中創建數據的編輯的副本,你需要像

q)t:update size:300 from(select from trade)where sym=`c,price>71 
q)t 
date  sym time   price size 
----------------------------------------- 
2007.07.23 a 04:48:52.665 73.53941 1000 
2007.07.23 a 04:48:52.675 81.73358 600 
2007.07.23 a 04:48:52.725 78.79526 900 
2007.07.23 a 04:48:52.735 79.59502 600 
2007.07.23 b 04:48:52.655 84.59765 200 
2007.07.23 b 04:48:52.685 98.36199 500 
2007.07.23 b 04:48:52.705 97.49875 700 
2007.07.23 c 04:48:52.645 61.48308 900 
2007.07.23 c 04:48:52.695 61.53192 700 
2007.07.23 c 04:48:52.715 71.95405 300 
q) 

如果要更改磁盤上的數據,這是相當難以在一般的情況下。在這種特殊情況下,你可以做這樣的:

q){.Q.dd[.Q.par[`:.;x;`trade];`]set update size:300 from(select from trade where date=x)where sym=`c,price>71}2007.07.23 
`:./2007.07.23/trade/ 
q)\l . 
q)trade 
date  sym time   price size 
----------------------------------------- 
2007.07.23 a 04:48:52.665 73.53941 1000 
2007.07.23 a 04:48:52.675 81.73358 600 
2007.07.23 a 04:48:52.725 78.79526 900 
2007.07.23 a 04:48:52.735 79.59502 600 
2007.07.23 b 04:48:52.655 84.59765 200 
2007.07.23 b 04:48:52.685 98.36199 500 
2007.07.23 b 04:48:52.705 97.49875 700 
2007.07.23 c 04:48:52.645 61.48308 900 
2007.07.23 c 04:48:52.695 61.53192 700 
2007.07.23 c 04:48:52.715 71.95405 300 
q)