Kdb 如何从表中删除多个列?

Kdb 如何从表中删除多个列?,kdb,q-lang,Kdb,Q Lang,因此,有deletecol from table来删除单个列。我想我可以使用over删除多个列。但是: 我不确定这是否有效 我不太清楚这里怎么正确使用。像这样的东西不起作用:{delete y from x}/[t;`name`job] 您可以用选择多列的相同方式删除多列 delete col1,col2 from table 在这种情况下,过度使用肯定会降低效率 但是,在一些示例中,您可能希望将列名作为符号传递给执行select或delete操作的函数 为此,需要使用delete的函数形式

因此,有
deletecol from table
来删除单个列。我想我可以使用
over
删除多个列。但是:

  • 我不确定这是否有效

  • 我不太清楚这里怎么正确使用。像这样的东西不起作用:
    {delete y from x}/[t;`name`job]


您可以用选择多列的相同方式删除多列

delete col1,col2 from table
在这种情况下,过度使用肯定会降低效率

但是,在一些示例中,您可能希望将列名作为符号传递给执行select或delete操作的函数

为此,需要使用delete的函数形式:

functinoal delete示例

q)table:([]col1:1 2 3;col2:1 2 3;col3:10 20 30) 
q)//functional delete
q){![table;();0b;x]} `col1`col2
col3
----
10  
20  
30  
q)//inplace functional delete
q){![`table;();0b;x]} `col1`col2
`table
q)table
col3
----
10  
20  
30 

可以使用与选择多列相同的方法删除多列

delete col1,col2 from table
在这种情况下,过度使用肯定会降低效率

但是,在一些示例中,您可能希望将列名作为符号传递给执行select或delete操作的函数

为此,需要使用delete的函数形式:

functinoal delete示例

q)table:([]col1:1 2 3;col2:1 2 3;col3:10 20 30) 
q)//functional delete
q){![table;();0b;x]} `col1`col2
col3
----
10  
20  
30  
q)//inplace functional delete
q){![`table;();0b;x]} `col1`col2
`table
q)table
col3
----
10  
20  
30 

我无法评论etc211的解决方案,所以我刚刚开始另一篇回复文章

Hmm, functional delete doesn't seem to work when the list of columns is empty. I'd expect that not to touch the table at all, and yet it deletes all the rows in it instead. 
对于以上内容,为什么不创建一个函数来选择要删除的列呢

假设您的表t包含列名:
col1、col2、col3、col4
您想删除:
col5,col6

从q代码:

tgt_cols:`col5`col6;
filtered_cols: (cols t) inter tgt_cols;
if[0 < count filtered_cols;
    {![`t;();0b;x]} filtered_cols];
tgt_cols:`col5`col6;
过滤列:(列t)列间tgt列;
如果[0

上面将首先检查是否存在要删除的列;如果要删除的目标列存在,它将删除这些列。

我无法在etc211的解决方案下面发表评论,所以我刚刚开始另一篇回复文章

delete col1,col2 from table
Hmm, functional delete doesn't seem to work when the list of columns is empty. I'd expect that not to touch the table at all, and yet it deletes all the rows in it instead. 
对于以上内容,为什么不创建一个函数来选择要删除的列呢

假设您的表t包含列名:
col1、col2、col3、col4
您想删除:
col5,col6

从q代码:

tgt_cols:`col5`col6;
filtered_cols: (cols t) inter tgt_cols;
if[0 < count filtered_cols;
    {![`t;();0b;x]} filtered_cols];
tgt_cols:`col5`col6;
过滤列:(列t)列间tgt列;
如果[0

上面将首先检查是否存在要删除的列;如果要删除的目标列存在,它将删除这些列。

对于内存中的表,您也可以使用drop:

delete col1,col2 from table

对于内存中的表,也可以使用drop:


谢谢,函数式表单正是我需要的。嗯,当列列表为空时,函数式删除似乎不起作用。我希望它不会触及表,但它会删除表中的所有行。谢谢,函数形式正是我所需要的。嗯,当列列表为空时,函数删除似乎不起作用。我希望它根本不接触表,但它会删除表中的所有行。