BigQuery 从字符串列执行表达式

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

Bigquery execute expression from string column

问题

在BigQuery中,我有一个表,其中有一个需要动态替换和执行的表达式。

例如

配置表
表,条件
XYZ,“if(1>2,true,false)”

我尝试了立即执行的过程。

声明条件字符串默认值=(从config_table中选择条件);
声明SQL字符串;
设置SQL =“从other_table中选择* where @condition”;

使用条件作为条件立即执行SQL

它将该值替换为字符串而不是评估表达式。是否有一种方法可以将其替换为表达式?提前感谢。

英文:

In bigquery, ive a table which has an expression which needs to be dynamically substituted and executed.

Eg

Config table
Table, condition
XYZ, "if(1>2,true,false)"

I tried procedural execute immediately.

Declare condition string default = (select condition from config_table);
Declare SQL string;
Set SQL ="Select * from other_table Where @condition";

Execute immediate SQL using condition as condition

It is replacing the value as string instead of evaluating the expression. Is there any way to substitute it as an expression ? Thanks in advance.

答案1

得分: 1

Declare condition string default (select condition from config_table);
Declare SQL string;
Set SQL ="Select * from other_table Where %s";

Execute immediate format(SQL, condition)

考虑如下:

声明条件字符串默认为(从config_table中选择条件);
声明SQL字符串;
设置SQL为“从other_table中选择* Where %s”;

立即执行格式(SQL, condition)
英文:

Consider below:

Declare condition string default (select condition from config_table);
Declare SQL string;
Set SQL ="Select * from other_table Where %s";

Execute immediate format(SQL, condition)

huangapple
  • 本文由 发表于 2023年7月11日 12:41:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76658762.html
匿名

发表评论

匿名网友

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

确定