select q kdb 历史数据库中除两列外的所有列

select all columns except two in q kdb historical database

在输出中,我想 select 除了来自 q/kdb 历史数据库中 table 的两列之外的所有列。 我在下面的查询中尝试了 运行,但它在 hdb 上不起作用。

delete colid,coltime from table where date=.z.d-1

但失败并出现以下错误

ERROR: 'par 
(trying to update a physically partitioned table)  

我提到了 https://code.kx.com/wiki/Cookbook/ProgrammingIdioms#How_do_I_select_all_the_columns_of_a_table_except_one.3F 但没有帮助。
我们如何显示kdb历史数据库中除两列之外的所有列?

可以试试函数式 select:

?[table;enlist(=;`date;.z.d);0b;{x!x}cols[table]except`colid`coltime]

这里的最后一个参数是列名到列标题的字典,它告诉查询要提取的内容。而不是删除您指定的列 select 除了那两个之外的所有列,它们或多或少是相同的查询。

要查看查询的函数形式是什么,您可以运行像这样:

parse"select colid,coltime from table where date=.z.d"

它会将参数输出到函数 select。

您可以在 functional selects at code.kx.com 上阅读更多内容。

您收到 par 错误的原因是它是一个分区 table。

记录错误 here

 trying to update a partitioned table 

您不能直接 updatedelete 分区 table 上的任何内容(有一个单独的数据库维护脚本)

您用作修复的查询基本上是先在内存中(临时)选择数据,然后删除列,因此它正在运行。

delete colid,coltime from select from table where date=.z.d-1

您可以试试下面的函数形式:

c:cols[t] except `p
?[t;enlist(=;`date;2015.01.01) ;0b;c!c]

只有 select 查询在分区的 table 上工作,您通过构建查询解决了这个问题,您首先 select 将 table 编辑到内存中,然后删除了您不想要的列。

如果您有大量列并且不想创建庞大的 select 查询,您可以使用函数式 select。

?[table;();0b;{x!x}((cols table) except `colid`coltime)]

并显示所有列 除了 列的子集。列子句需要一个字典,因此我使用函数 {x!x} 将我的列表转换为字典。在此处查看更多信息

https://code.kx.com/q/ref/funsql/

正如 nyi 提到的,如果你想从历史数据库中永久删除列,你可以使用 dbmaint 工具中的 deleteCol 函数 https://github.com/KxSystems/kdb/blob/master/utils/dbmaint.md