英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论