如何在update语句中使用amend

问题描述 投票:0回答:1

我们有一个表格选项卡

tab:update volume:0n from ([] date:2024.01.01+til 10;sym:10?`appl`msgt`googl;volume:10#(enlist 0.5+300?til 100)) where i in (1;5;8);

enter image description here

我们希望通过以下方式更新列卷:将索引 299 的存储桶值复制到 200,并将零存储桶 201 复制到 299。

我们可以使用这样的修改来做到这一点,但是当卷为空/空时,修改会抛出类型错误。

在此行为中,我们希望不抛出错误,而是按原样返回空/空,并且仅当卷列中有内容时才进行处理。

//original value
first exec volume from select from tab where i=0

enter image description here

//updated expected values, works where volume is not null else gives type error
first exec volume from {[start;end;tab] tt:.[tab;(::;`volume;200);:;.[tab;(::;`volume;299)]]; .[tt;(::;`volume;start+til end-start);:;0f]}[201;299;select from tab where i=0]

enter image description here

但是当我们传递整个表时,这会产生类型错误,其中体积为空

first exec volume from {[start;end;tab] tt:.[tab;(::;`volume;200);:;.[tab;(::;`volume;299)]]; .[tt;(::;`volume;start+til end-start);:;0f]}[201;299;select from tab]

我们检查卷是否为空然后返回 null/empty 执行其他操作进行处理的最佳方法是什么 像这样的东西

update volume:{ $[count x;"do processing here using amend"; x] }'[volume] from tab
kdb
1个回答
0
投票
q)update volume:{$[1=count x;x;@[;y+til z-y;:;0f]@[x;200;:;x 299]]}'[volume;201;299]from tab
© www.soinside.com 2019 - 2024. All rights reserved.