【问题标题】:Update nested list of tables in KDB table更新 KDB 表中的嵌套表列表
【发布时间】:2021-02-11 16:53:08
【问题描述】:

我有下表,我正在尝试更新表的嵌套列表的空模式并在 t1 中使用结果填充它们

t:flip (`userName`nestedList)!(("user1";"user2";"user3";"user4");(flip (`col1`col2`col3`col4`col5`col6`col7)!(`symbol$();();();();();();());flip (`col1`col2`col3`col4`col5`col6`col7)!(enlist `XXX_XXX;enlist 0b;enlist 2000j;enlist -1j;enlist 1b;enlist 0b;enlist 0b);flip (`col1`col2`col3`col4`col5`col6`col7)!(`symbol$();();();();();();());flip (`col1`col2`col3`col4`col5`col6`col7)!(enlist `XXX_XXX;enlist 0b;enlist 2000j;enlist -1j;enlist 1b;enlist 0b;enlist 0b)))

期望的结果是 t1

t1:flip (`userName`nestedList)!(("user1";"user2";"user3";"user4");(flip (`col1`col2`col3`col4`col5`col6`col7)!(enlist `;enlist 0b;enlist 0;enlist 0;enlist 0b;enlist 0b;enlist 0b);flip (`col1`col2`col3`col4`col5`col6`col7)!(enlist `XXX_XXX;enlist 0b;enlist 2000j;enlist -1j;enlist 1b;enlist 0b;enlist 0b);flip (`col1`col2`col3`col4`col5`col6`col7)!(enlist `;enlist 0b;enlist 0;enlist 0;enlist 0b;enlist 0b;enlist 0b);flip (`col1`col2`col3`col4`col5`col6`col7)!(enlist `XXX_XXX;enlist 0b;enlist 2000j;enlist -1j;enlist 1b;enlist 0b;enlist 0b)))

//试图更新 t,所以下面运行的计数是 4 而不是 2

raze exec nestedList from t //count=2

raze exec nestedList from t1 //count=4

感谢您的帮助!

【问题讨论】:

    标签: kdb


    【解决方案1】:

    这是一种方法。

    q)update nestedList:count[i]#enlist flip`col1`col2`col3`col4`col5`col6`col7!1#'(`;0b;0;0;0b;0b;0b)from t where userName in("user1";"user3")
    userName nestedList
    -----------------------------------------------------------------------------------
    "user1"  +`col1`col2`col3`col4`col5`col6`col7!(,`;,0b;,0;,0;,0b;,0b;,0b)
    "user2"  +`col1`col2`col3`col4`col5`col6`col7!(,`XXX_XXX;,0b;,2000;,-1;,1b;,0b;,0b)
    "user3"  +`col1`col2`col3`col4`col5`col6`col7!(,`;,0b;,0;,0;,0b;,0b;,0b)
    "user4"  +`col1`col2`col3`col4`col5`col6`col7!(,`XXX_XXX;,0b;,2000;,-1;,1b;,0b;,0b)
    q)t1~update nestedList:count[i]#enlist flip`col1`col2`col3`col4`col5`col6`col7!1#'(`;0b;0;0;0b;0b;0b)from t where userName in("user1";"user3")
    1b
    q)count raze exec nestedList from update nestedList:count[i]#enlist flip`col1`col2`col3`col4`col5`col6`col7!1#'(`;0b;0;0;0b;0b;0b)from t where userName in("user1";"user3")
    4
    

    如果您需要 where 子句来考虑 nestedList 列,则可以使用

    q)t1~update nestedList:count[i]#enlist flip`col1`col2`col3`col4`col5`col6`col7!1#'(`;0b;0;0;0b;0b;0b)from t where not count each nestedList
    1b
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      • 1970-01-01
      • 2016-09-13
      • 1970-01-01
      相关资源
      最近更新 更多