kdb 函数中的字符串查询

string query in a function in kdb

func:{[query] value query};

查询是我职能的一部分。我添加了一些像 delete xxx, yyyy from (value query) 和一些操作。我不确定为什么当我不使用值 "query" 时,该功能不起作用。它说找不到 table。所以我必须在函数中使用值查询,查询是一个参数。我需要将 "select from tab" 传递给函数。

我的问题是:如果过滤器也是字符串,我该如何发送?

func["select from tab where a="abc""] <<< this does not work

如何使字符串中的字符串起作用?

此外,不确定为什么要这样做

func["select from tab where date = max date"]  it did not work due to length error
but func["100#select from tab where date = max date"] it works ?

整个函数是

getTable:{[query]loadHDB[];.Q.view date where date < .z.D-30;tab:(delete xxxx,yyyyy,sub,ID,subID,tID,subTID,text,gID from((value query)));remove[];update {";"sv @[s;where (s:";"vs x) like "cId=*";:;enlist""]}each eData from (update {";"sv @[s;where (s:";"vs x) like "AId=*";:;enlist""]}each eData from tab)}; 


remove:{[]delete tab from `.};
loadHDB:{[]value "\l /hdb};

您可以使用反斜杠转义引号 http://code.kx.com/wiki/Reference/BackSlash#escape

func["select from tab where a like \"abc\""] 

编辑:

如果选项卡是 HDB table 那么这个长度错误可能指向列长度问题(100# 正在避免)。以下return是什么?

q)checkPartition:{[dt] a!{c!{count get x} each ` sv' x,/:c:({x where not x like "*#"} key[x])except `.d}each a:(` sv' d,/:key[d:hsym `$string dt])};
q)check:checkPartition last date
q)(where{1<count distinct value x}each check)#check

我喜欢用-3!还有 -1 来打印结果。如果您知道如果从控制台执行查询应该是什么样子,那么在构造字符串后,使用 -1 打印字符串。它应该按照控制台执行的方式打印查询。

    q)stst:-3!
    q)"select max age by user from tab where col1 like ",stst"Hello"
    "select max age by user from tab where col1 like \"Hello\""
    q)/then to view how it will be executed, use -1
    q)-1"select max age by user from tab where col1 like ",stst"Hello";
    select max age by user from tab where col1 like "Hello"
    q)/looks good