简体   繁体   中英

How to insert into ARRAY<STRING> column in BQ stored Proc

I am trying to create BQ routine which takes ARRAY as parameter and insert into table.

filename can be NULL too.

CREATE OR REPLACE PROCEDURE `##.history`( Job_ID STRING, filename ARRAY<STRING> , Status STRING )
BEGIN
 
  
  EXECUTE IMMEDIATE format 
  ("""
  INSERT INTO  
  `##.tablename`
  ( JOB_ID,
   FILENAME,
   STATUS,
    )
  values
   (GENERATE_UUID(),
    '"""||Job_ID||"""',
     '"""||filename|| """',
     '"""||Status||"""'
    )
   """);

when I am invoking procedure it's giving error:

CALL ###.history ('text1', ['f1.txt','f2.txt'], 'start');

No matching signature for operator || for argument types: STRING, ARRAY. Supported signatures: STRING || STRING; BYTES || BYTES; ARRAY || ARRAY

Your error is coming from the format statement and trying to concatenate the array, concatenation being a string function only. As Max Zolotenko pointed out, you probably don't need the EXECUTE IMMEDIATE in the example you provided, you can proceed with something like:

CREATE OR REPLACE PROCEDURE `so_test.history`( Job_ID STRING, filename ARRAY<STRING> , Status STRING )
BEGIN
 
  
INSERT INTO so_test.struct_insert (job_id, filename, status)
VALUES
(
  Job_ID,
  filename,
  Status
);

END;

I do want to point out however in your example you have GENERATE_UUID() that you are also trying to insert, however your values list only contains 3 columns. You'll need to adjust that as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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