如何通过其名称引用列变量?

huangapple go评论59阅读模式
英文:

How to refer to a column variable by its name?

问题

我的脚本如上所示其中 `col` 是一个字符串变量我如何使用列名字符串变量来引用列变量我如何修改脚本以确保成功执行
英文:

如何通过其名称引用列变量?

My script is as shown above, where col is a string variable. How can I use the column names (string variables) to refer to column variables?How can I modify the script to ensure a successful execution?

答案1

得分: 1

根据上述脚本,我们可以推断您想要填充列中的空值。您可以使用nullFill函数:

t = table(1.0 2.0 NULL 3.3 as open, NULL 1.3 NULL 2.2 as low)
nullFill(t, 0)

tb_fj[col, <isNull(col)>]中,col必须是一个列变量,而不是一个字符串。您可以参考以下代码:

id = 1..10
x = rand(NULL 10.0, 10)
t = table(id, x as x1)
colName = `x1
t[colName, isNull(t[colName])] = 0

在其他情况下,您可以使用objByName按名称返回一个变量,并使用funcByName按名称执行一个函数。在SQL元编程中,您可以使用sqlCol按名称返回一个列。

英文:

According to the above script, we can infer that you want to fill the NULL values in the column. You can use the nullFill function:

t = table(1.0 2.0 NULL 3.3 as open, NULL 1.3 NULL 2.2 as low)
nullFill(t, 0)

In tb_fj[col, <isNull(col)>], col must be a column variable, rather than a string. You can refer to the following code:

id = 1..10
x = rand(NULL 10.0, 10)
t  = table(id, x as x1)
colName=`x1
t[colName, isNull(t[colName])] = 0

In other cases, you can use objByName to return a variable by its name, and funcByName to execute a function by its name. In SQL metaprogramming, you can use sqlCol to return a column by its name.

huangapple
  • 本文由 发表于 2023年4月4日 16:30:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75927158.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定