简体   繁体   English

bigquery 中的数组结构

[英]Array Struct in bigquery

When calling the procedure below with input as array of struct, I am getting an error.当使用输入作为结构数组调用下面的过程时,出现错误。 Code has compiled fine but I'm getting error while calling.代码编译正常,但调用时出现错误。

CREATE OR REPLACE PROCEDURE `linear-charmer-344806.2143.Test4`(IN v_name_struct ARRAY<struct<roll numeric,dept string>>, OUT id ARRAY<STRING>)
begin 

for i in (select x.roll,x.dept from unnest(v_name_struct)as x)
do
update `linear-charmer-344806.2143.Employee` 
set salary='1000'
where roll=i.roll;
end for;

end;

DECLARE v_name_struct ARRAY<STRUCT<roll NUMERIC, dept STRING>> DEFAULT NULL;
DECLARE id ARRAY<STRING> DEFAULT NULL;
CALL `linear-charmer-344806.2143.Test4`([(2,'ECE')], id);--Getting error in this

Besides the comment about the output of your procedure.除了关于您程序的 output 的评论。 I think I will do the following to address your issue:我想我会做以下事情来解决你的问题:

CREATE OR REPLACE PROCEDURE `projectid.dataset.proc_test4`(IN v_name_struct ARRAY<struct<roll numeric,dept string>>, OUT id ARRAY<STRING>)
begin 

for i in (select x.roll,x.dept from unnest(v_name_struct)as x)
do

    update `projectid.dataset.Employee_test4`
    set salary='1000'
    where roll=i.roll;

end for;

set id = (select [dept] from `projectid.dataset.Employee_test4` where salary="1000");

end;

As you can see below, you have to pass the variables you are setting in your procedure.正如您在下面看到的,您必须传递您在过程中设置的变量。 In this case, if you do not pass numeric type you will get errors.在这种情况下,如果您不传递numeric类型,您将收到错误消息。 You can use cast to convert the value to numeric .您可以使用cast将值转换为numeric

DECLARE v_name_struct ARRAY<STRUCT<roll NUMERIC, dept STRING>> DEFAULT NULL;
DECLARE id ARRAY<STRING> DEFAULT NULL;

set v_name_struct = [(cast(2 as numeric),'ECE')];
CALL `projectid.dataset.proc_test4`(v_name_struct, id);
select id;

For additional information about cast you can check following link:有关演员表的其他信息,您可以查看以下链接:

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

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