首页 > 解决方案 > deleting all records for all tables in memory in Kdb+

问题描述

I would like to delete all records for all tables in memory but still keep the schemas.

for example:

a:([]a:1 2;b:2 4);
b:([]c:2 3;d:3 5);

I wrote a function:

{[t] t::select from t where i = -1} each tables[]

this didnt work, so i tried

{[t] ![`t;enlist(=;`i;-1);0b;()]} each tables[]

didnt work either. Any idea or better ways?

标签: kdb

解决方案


Mark 的解决方案最适合做你想做的事情,而不是功能形式。只是添加关于 t 失败的问题,因为将 kdb 代码放在注释中是很尴尬的。

您的功能形式失败不是因为t而是因为您的最后一个参数不是符号列表`$()。您还想删除 where iis > -1,而不是=

q){[t] ![t;enlist(>;`i;-1);0b;`$()]} each `d`t`q
`d`t`q

q)d
date sym time bid1 bsize1 bid2 bsize2 bid3 bsize3 ask1 asize1 ask2 asize2 ask..
-----------------------------------------------------------------------------..
q)t
date sym time src price size
----------------------------
q)q
date sym time src bid ask bsize asize
-------------------------------------


推荐阅读