首页 文章

kdb中函数中的字符串查询

提问于
浏览
0
func:{[query] value query};

查询是我的功能的一部分 . 我添加了一些像删除xxx,yyyy(值查询)和一些操作 . 我不确定为什么当我不使用值“查询”时,该功能不起作用 . 它说它找不到表 . 所以我必须在函数中使用值查询,查询是一个参数 . 我需要将“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};

2 回答

  • 1

    我喜欢用-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
    
  • 3

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

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

    编辑:

    如果tab是HDB表,则此长度错误可能指向列长度问题(100#正在避免) . 以下是什么回报?

    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
    

相关问题