kdb:从 HDB 获取一行

kdb: getting one row from HDB

对于正常的 table,我们可以使用 select[1] from t select 一行。我该如何为 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

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

1#select from t where date=2021.02.25
如果应用于已加载的数据,

select[n] 将起作用,例如

select[1] from select from t where date=2021.02.25

我之前通过使用虚拟索引 i 对临时查询执行过此操作,这应该避免将所有数据拉入内存仅 select 几行的成本。如果您的查询需要在提取子集之前先映射约束,这是一个合理的解决方案。

然而,由于 q 查询在幕后工作的方式,它将为每个日期分区提取 N 行 selected。所以 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]

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

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

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

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

实现
.Q.ind[t;enlist 0]