更新符号长度小于 3 个字符的 KDB+/Q

update where symbol length less than 3 characters KDB+/Q

提问人:Cole MG 提问时间:1/11/2022 更新时间:1/12/2022 访问量:584

问:

我有一张这样的表格:

test:([]column1:`A`B`C`D`E;column2:`Consumer`RealEstate`27`85`Technology)

我需要编写一个更新查询,其中 column2 的字符数为 2 或更少,但我找不到任何方法来引用要在 where 子句中使用的符号的字符长度。我将如何编写这样的查询,以便我的结果如下?

test:([]column1:`A`B`C`D`E;column2:`Consumer`RealEstate`NewCategory`NewCategory`Technology)
sql-update kdb q

评论


答:

5赞 kylebonnes 1/11/2022 #1

实现所需目的的一种方法是将符号转换为字符串(即字符列表),并将 where 子句应用于每个字符串的计数:

update column2:`NewCategory from `test where 3>count each string column2

(此处在表名上使用反引号,假设您要就地应用更改)

1赞 Scott 1/12/2022 #2

另一种选择是使用向量条件

update column2:?[3>count each string column2;`NewCatergory;column2] from test