要删除包含正则表达式的KDB列表中的条目?

时间:2019-06-07 08:41:24

标签: kdb

如何在KDB表中删除与某个正则表达式匹配的行?

例如:

初始表

index | value  | number
  0   |  a_fo  |  999
  1   |  b_fo  |  999
  2   |  c_fo  |  999
  3   |  c_ba  |  999

查询应删除value列中与正则表达式c_*匹配的所有条目,其中值以{​​{1}}开头,之后是任意长度的字符。

结果表

c_

2 个答案:

答案 0 :(得分:3)

或者,您可以编入索引以避免更快地使用删除模板

t where not t[`value] like "c*"

或者使用功能性删除

![t;enlist(like;`value;"c_*");0b;`$()]

关于命名列值(这是q中的保留关键字),您可以使用.Q.id,它将重命名错误的变量以避免任何问题,例如:

.Q.id t
results in the columns `index`value1`number

答案 1 :(得分:2)

首先,我不会将列命名为值。这将导致错误。

index val  number
-----------------
0     a_fo 999
1     b_fo 999
2     c_fo 999
3     c_ba 999

使用Delete即可完成

t:delete from t where val like "c_*"

如果要更新表,则需要重新定义t。