我正在尝试从表中删除一列而不丢失数据,以便可以再次恢复数据,但是当q进程加载表时,将不会显示已删除的列。显然我下面的代码无法正常工作。 q有什么可以做到的吗? dir是表所在的位置,c是要删除的列。
{[dir;t;c] delete c from (` sv (dir,t),`)}
答案 0 :(得分:5)
kdb +提供了一种“删除”列的简便方法,而无需实际删除列数据。如果查看存储表的目录,则应该能够识别.d
文件。 kdb +在此处存储表列的正确顺序。要删除列,只需从此.d
文件中删除列名。例如:
q)get `:test/.d
`sym`time`src`bid`ask`bsize`asize
q)
q)`:test/.d set `sym`time`src`bid`ask`bsize
`:test/.d
q)
q)test
sym time src bid ask bsize asize
--------------------------------------------------------------
AAPL 2014.04.21D08:00:00.456000000 L 25.32 25.36 8000 8500
AAPL 2014.04.21D08:00:01.387000000 O 25.32 25.35 9500 2500
AAPL 2014.04.21D08:00:10.348000000 N 25.35 25.35 8000 5000
AAPL 2014.04.21D08:00:10.532000000 L 25.33 25.37 5000 7000
AAPL 2014.04.21D08:00:15.163000000 L 25.34 25.36 10000 8000
AAPL 2014.04.21D08:00:15.847000000 N 25.32 25.36 1500 500
AAPL 2014.04.21D08:00:16.335000000 N 25.33 25.34 8500 5500
AAPL 2014.04.21D08:00:17.017000000 N 25.33 25.34 9000 2500
AAPL 2014.04.21D08:00:17.634000000 N 25.3 25.36 9500 1000
AAPL 2014.04.21D08:00:19.427000000 L 25.33 25.36 9500 5000
AAPL 2014.04.21D08:00:24.629000000 N 25.33 25.37 6000 2000
AAPL 2014.04.21D08:00:25.207000000 L 25.33 25.36 5000 2500
AAPL 2014.04.21D08:00:29.962000000 L 25.32 25.38 3500 5000
AAPL 2014.04.21D08:00:31.998000000 O 25.34 25.36 5500 4000
AAPL 2014.04.21D08:00:33.795000000 N 25.34 25.36 5000 3500
AAPL 2014.04.21D08:00:34.651000000 L 25.35 25.37 7500 6500
AAPL 2014.04.21D08:00:38.843000000 O 25.33 25.36 4000 6500
AAPL 2014.04.21D08:00:40.062000000 L 25.33 25.38 2000 9500
AAPL 2014.04.21D08:00:43.508000000 N 25.35 25.36 6500 10000
AAPL 2014.04.21D08:00:46.823000000 N 25.35 25.38 6000 7500
..
q)\l .
q)test
sym time src bid ask bsize
--------------------------------------------------------
AAPL 2014.04.21D08:00:00.456000000 L 25.32 25.36 8000
AAPL 2014.04.21D08:00:01.387000000 O 25.32 25.35 9500
AAPL 2014.04.21D08:00:10.348000000 N 25.35 25.35 8000
AAPL 2014.04.21D08:00:10.532000000 L 25.33 25.37 5000
AAPL 2014.04.21D08:00:15.163000000 L 25.34 25.36 10000
AAPL 2014.04.21D08:00:15.847000000 N 25.32 25.36 1500
AAPL 2014.04.21D08:00:16.335000000 N 25.33 25.34 8500
AAPL 2014.04.21D08:00:17.017000000 N 25.33 25.34 9000
一旦删除,kdb +将不会将该列与您的表关联,并且在调用内存时将不会显示该列。
希望这会有所帮助。