简体   繁体   中英

Update a struct column in bigquery using another table in bigquerry having string columns

I have a table A with schema

ID -> type(String)
experience -> type(Array of Struct)

A.experience column has 6 subfield of type string.

I wish to update A.experience using another table B(which can be joined on basis of ID) and has 6 more columns which correspond to keys in A.experience.

All the columns in table B are of type String.

Here's what I tried

update  A
set A.experience = (company,starts_at,ends_at,eid,title,location) 
from B
where A.id = B.id;

Any help would be appreciated. Thanks!

Not sure I clearly understood your queston, but you seem to want to do this. let me know if I'm wrong.

CREATE TEMP TABLE A AS
SELECT 'id1' id, 
       [STRUCT('C1'AS company, '2010-01-01 11:00:00' AS starts_at, '2010-01-01 12:00:00' AS ends_at, 'eid1' AS eid, 'title1' AS title, 'loc1' AS location),
        STRUCT('C2', '2011-01-01 11:00:00', '2011-02-02 13:00:00', 'eid2', 'title2', 'loc2')] AS experience;

CREATE TEMP TABLE B AS 
SELECT 'id1' AS id, 'C2_new' company, '2011-02-01 11:00:00' starts_at, '2011-03-02 13:00:00' ends_at, 'eid2_new' eid, 'title_new' title, 'loc2_new' location;

UPDATE A
   SET A.experience = ARRAY(SELECT AS STRUCT B.company, B.starts_at, B.ends_at, B.eid, B.title, B.location FROM UNNEST(A.experience))
  FROM B
 WHERE A.id = B.id;
 
SELECT * FROM A;

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