【问题标题】:kdb: getting one row from HDBkdb:从 HDB 获取一行
【发布时间】:2021-02-28 03:27:34
【问题描述】:

对于普通表格,我们可以使用select[1] from t 选择一行。我怎样才能为 HDB 做到这一点?


我试过select[1] from t where date=2021.02.25,但它给出了错误

Not yet implemented: it probably makes sense, but it’s not defined nor implemented, and needs more thinking about as the language evolves

【问题讨论】:

    标签: kdb


    【解决方案1】:

    select[n] 语法仅在表已加载到内存中时才有效。 获取 HDB 表第一行的最简单方法是:

    1#select from t where date=2021.02.25
    

    select[n] 如果应用于已加载的数据,例如

    ,则将起作用
    select[1] from select from t where date=2021.02.25
    

    【讨论】:

      【解决方案2】:

      我之前使用虚拟索引 i 为临时查询完成了此操作,这样可以避免将所有数据拉入内存以选择几行的成本。如果您的查询需要在提取子集之前先映射约束,这是一个合理的解决方案。

      但是,由于 q 查询在幕后工作的方式,它将为每个选定的日期分区提取 N 行。所以 YMMV,如果它在 API 之后,这可能不是最好的解决方案。

      / 5 rows (i[5] is the 6th row)
      select from t where date=2021.02.25, sum=`abcd, price=1234.5, i<i[5]
      

      【讨论】:

        【解决方案3】:

        如果你的表是日期分区的,你可以简单地运行

        select col1,col2 from t where date=2021.02.25,i=0
        

        这将从2021.02.25的分区中获取第一条记录,并避免将每条记录都加载到内存中。

        根据您的第一个请求(与上述不同)select[1] from t,您可以使用

        .Q.ind[t;enlist 0]
        

        【讨论】:

          猜你喜欢
          • 2015-02-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多