不知何故,我只能找到显示如何添加一列的示例。
所以我编写了这段代码,它可以工作,但我知道有一种更好的方法可以做到这一点:表 t 已经存在,其中列填充了数据,我需要添加最初为空的新列。
t: update column1:` from t;
t: update column2:` from t;
t: update column3:` from t;
t: update column4:` from t;
Run Code Online (Sandbox Code Playgroud)
我尝试将其设为一个函数:
colNames:`column1`column2`column3`column4;
t:{update x:` from t}each colNamesList;
Run Code Online (Sandbox Code Playgroud)
但这只添加了一列并将其称为x。
任何改进此代码的建议将不胜感激。我必须添加的不仅仅是 4 列,因此我的代码很长。谢谢你!
实现这一目标的各种方法......
q)newcols:`col3`col4;
q)@[tab;newcols;:;`]
col1 col2 col3 col4
-------------------
a 1
b 2
c 3
Run Code Online (Sandbox Code Playgroud)
还可以指定不同类型
q)@[tab;newcols;:;(`;0N)]
col1 col2 col3 col4
-------------------
a 1
b 2
c 3
Run Code Online (Sandbox Code Playgroud)
或者进行功能更新
q)![`tab;();0b;newcols!count[newcols]#enlist (),`]
`tab
Run Code Online (Sandbox Code Playgroud)