从KDB中的混合类型行中选择值

use*_*448 0 kdb q-lang

我们用类型C(即字符数组)定义了我们的KDB表.我们插入的第一个值有一个String类型.第二个值的类型为int(即i).现在,当我们尝试使用条件查询KDB时,where like="value"它不起作用.因为我们在一列中有混合类型,我们如何where根据此列查询数据并过滤它(在子句中使用)?

ter*_*nch 5

我几乎不想在这里给出解决方案,因为在一列中将字符串与整数混合是一个可怕的想法.完全破坏性能并防止kdb提供的任何好处.

首先,重新考虑您的设置.

如果您坚持保持原样,可以像这样查询:

tab:([] col1:`a`b`c;col2:1 2 3;col3:("foo";"bar";1i))
Run Code Online (Sandbox Code Playgroud)

用于精确匹配

q)select from tab where col3~\:"foo"
col1 col2 col3
---------------
a    1    "foo"

q)select from tab where col3~\:1i
col1 col2 col3
--------------
c    3    1
Run Code Online (Sandbox Code Playgroud)

用于正则表达式匹配

q)select from tab where {$[10h=type x;x like "f*";0b]}'[col3]
col1 col2 col3
---------------
a    1    "foo"
Run Code Online (Sandbox Code Playgroud)

但是不要说你没有被警告或建议不要!