KDB從

2017-05-24 36 views
0

選擇正則表達式有沒有辦法使用正則表達式來定義select語句中的所有列。像KDB從

select myColumnPrefix* from myTable 

這將顯示所有以myColumnPrefix開頭的列?

回答

3

不使用qSQL,但是您可以使用正則表達式來獲取列名稱,然後使用功能選擇。例如,

c: cols[myTable] where cols[myTable] like "myColumnPrefix*"; 
?[myTable;();0b;c!c] 

或者作爲一個內膽,

?[myTable;();0b;{[email protected]:where x like "myColumnPrefix*"} cols myTable] 
1

如果你真的想使用QSQL(不建議 - 難讀/維護),那麼你可以在@ostewart建議擴大了什麼:

定義表:

q)t:([]foo1:1 2;foo2:3 4;foo3:5 6;bar1:1 2;bar2:3 4;bar3:5 6) 
q)t 
foo1 foo2 foo3 bar1 bar2 bar3 
----------------------------- 
1 3 5 1 3 5 
2 4 6 2 4 6 

的興趣提取列,並準備爲字符串:

q)c:", " sv string cols[t] where cols[t] like "foo*"; 
q)c 
"foo1, foo2, foo3" 

聯接列來選擇查詢和值表達式:

q)value "select ",c," from t" 
foo1 foo2 foo3 
-------------- 
1 3 5 
2 4 6