【问题标题】:string query in a function in kdbkdb函数中的字符串查询
【发布时间】:2017-06-07 20:54:32
【问题描述】:
func:{[query] value query};

查询是我的功能的一部分。我添加了一些像 delete xxx, yyyy from (value query) 和一些操作。我不知道为什么当我不使用值“查询”时,该功能不起作用。它说它找不到桌子。所以我必须在函数中使用值查询,查询是一个参数。我需要将“从选项卡中选择”传递给函数。

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

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};

【问题讨论】:

    标签: kdb


    【解决方案1】:

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

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

    编辑:

    如果选项卡是 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
    

    【讨论】:

    • 很好用!但是你知道为什么当我在函数中进行查询时它给出了长度错误。如果我没有指定要从查询中获得多少条记录,则会出现错误。不过,我的功能没有任何问题
    • 如果选项卡是 HDB 表,则此长度错误可能指向列长度问题(100# 正在避免)。以下是什么(将代码移动到已编辑的答案)
    • 哦,如果我删除#check,它会返回第n个
    • 我也发现了,如果我设置了一个条件,那么只有在 cols 选项卡中的 eData,它运行你在另一个线程中给我的函数,如果不只是返回选项卡的话。然后该功能以更好的方式工作。
    • 您好康纳,很抱歉,公司内的聊天被屏蔽了。 func["select from tab"] 在指定 where date = max date 时返回相同的长度错误。但是 ["select col from tab"] 返回一些东西。我稍微改变了功能。因此,如果返回表中没有 eData 列,则不会执行替换值的函数。不确定是否存在 eData 列中替换值函数的长度错误。我在家时可以打开聊天。谢谢康纳
    【解决方案2】:

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

    【讨论】:

    • 小心控制台大小.. :) q)system"c 50 10" q)-3!"Hello" "\"Hell..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 2015-08-13
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多