简体   繁体   English

可以将表达式传递给 BigQuery 中的限制

[英]Possible to pass an expression to a limit in BigQuery

Is there any workaround to accomplish something like the following in BigQuery:是否有任何解决方法可以在 BigQuery 中完成以下操作:

select 1 limit (select 1)
select 1 limit 2-1

In other words, pass an expression to the LIMIT keyword?换句话说,将表达式传递给LIMIT关键字? Or, is there no possible way to emulate that behavior?或者,有没有可能模仿这种行为的方法?

Folowing the link provided, you can build it like this按照提供的链接,您可以像这样构建它

DECLARE lim DEFAULT (SELECT 1);

EXECUTE IMMEDIATE """
 select 1 LIMIT ?
"""
USING  lim;

Or, is there no possible way to emulate that behavior?或者,有没有可能模仿这种行为的方法?

I would rather go with below approach我宁愿 go 采用以下方法

select * 
from your_table 
qualify row_number() over() < (select 15 - 2)      

or in more practical case - something like或者在更实际的情况下 - 类似

select * 
from your_table 
qualify row_number() over() < (select limit_value from other_table limit 1 )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM