You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

kdb中date列空单元格填充0Nd空日期值的实现问题

kdb date列空值替换实现方案

正确实现代码

如果你需要精确匹配排除product为"Debet:Loan"的行,使用效率更高的等值判断版本:

data: update date:0Nd^date from data where product <> "Debet:Loan";

如果你需要模糊匹配排除所有包含"Debet:Loan"的product行,使用like版本:

data: update date:0Nd^date from data where not product like "*Debet:Loan*";

注意:如果product列为symbol类型,需要把匹配值改为symbol格式,比如把"Debet:Loan"替换为 `Debet:Loan

代码逻辑说明

  • 0Nd^date:使用kdb的填充运算符^,将date列中所有date类型空值替换为0Nd,完全匹配date列的类型要求,不会出现类型报错。
  • where过滤条件:仅对符合条件的行执行替换操作,product为"Debet:Loan"的行不会被修改,完全符合需求的排除规则。

结果验证

执行查询语句即可看到和预期一致的结果:

select Class, product, date from data

输出结果:

Classproductdate
FirstDebet:Instru:*0Nd
FirstDebet:Instru:*0Nd
FirstDebet:Loan2020.10.12
FirstDebet:Loan2020.10.12

内容的提问来源于stack exchange,提问作者coderinq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 06:06:03