如何使用 BigQuery 中的存储函数 return 多个值?
How to return several values with Stored functions in BigQuery?
有什么方法可以 return bigquery 中的多个结果(存储函数)
我听说我们应该可以用 Array 来做。
这是一个例子:
create function if not exists hw6.GetNumTherapistWorking(
dateInput date
)
returns count1,count2,count3
as
(
(select count1,count2,count3 from table....);
)
考虑以下示例来说明解决方案
create temp table mytable as
select 1 count1, 2 count2, 3 count3, current_date as count_date union all
select 11, 12, 13, current_date - 3 union all
select 21, 22, 23, current_date - 5
;
# create function if not exists hw6.GetNumTherapistWorking(
create temp function GetNumTherapistWorking(dateInput date) as (
array(select as struct count1,count2,count3 from mytable where count_date > dateInput)
);
select *
from unnest(GetNumTherapistWorking(current_date - 4));
有输出
注意:它使用临时 UDF - 但同样适用于永久(存储)UDF - 您只需要使用完全限定的 UDF 名称 - hw6.GetNumTherapistWorking
有什么方法可以 return bigquery 中的多个结果(存储函数) 我听说我们应该可以用 Array 来做。 这是一个例子:
create function if not exists hw6.GetNumTherapistWorking(
dateInput date
)
returns count1,count2,count3
as
(
(select count1,count2,count3 from table....);
)
考虑以下示例来说明解决方案
create temp table mytable as
select 1 count1, 2 count2, 3 count3, current_date as count_date union all
select 11, 12, 13, current_date - 3 union all
select 21, 22, 23, current_date - 5
;
# create function if not exists hw6.GetNumTherapistWorking(
create temp function GetNumTherapistWorking(dateInput date) as (
array(select as struct count1,count2,count3 from mytable where count_date > dateInput)
);
select *
from unnest(GetNumTherapistWorking(current_date - 4));
有输出
注意:它使用临时 UDF - 但同样适用于永久(存储)UDF - 您只需要使用完全限定的 UDF 名称 - hw6.GetNumTherapistWorking