-1

I have the following function in postgres:

create function my_function(my_table mt, OUT e_p_l numeric, OUT e_p numeric) returns record
    language plpgsql
as
$$
BEGIN
    e_p_l := e_p_procedure(mt.p, mt.q_l, mt.m_c, mt.d_f);
    e_p := e_p_procedure(mt.p, mt.q, mt.m_c, mt.d_f);
END;
$$;

I have e_p_procedure successfully working in BigQuery. But the current error I have is

Type not found: mt

my_table is just as it seems, a table (aliased as mt) with various fields I'd like to input into a BigQuery Procedure replica of this Postgres function.

How can I accomplish this in BigQuery?

CREATE PROCEDURE my_schema.my_function(my_table mt, OUT e_p_l numeric, OUT e_p numeric) 
BEGIN
    SET e_p_l = e_p_procedure(mt.p, mt.q_l, mt.m_c, mt.d_f);
    SET e_p = e_p_procedure(mt.p, mt.q, mt.m_c, mt.d_f);
END;
4

1 回答 1

0

对于您的用例,您可以在 BigQuery 中执行动态语句,方法是使用EXECUTE IMMEDIATE语法在PROCEDURE.

你的脚本看起来像,

CREATE PROCEDURE my_dataset.my_procedure(tableName STRING, ...) 
BEGIN
EXECUTE IMMEDIATE CONCAT("SELECT column_name FROM ", tableName, " WHERE ...");
  ...
END

EXECUTE IMMEDIATE您可以在本文档中找到更多关于如何在不同用例中使用的示例。此外,这里是在 BigQuery中创建过程的文档。

于 2021-11-01T03:15:50.190 回答