0

This is a clarification/follow-up on the earlier question where I didn't specify the requirement for null values.

Given this input:

Row     id      app_date    inventor.name   inventor.country
1       id_1    01-15-2022  Steve           US
                            Ashley          US
2       id_2    03-16-2011  Pete            US
                            <null>          US
                            Mary            FR

I need to extract name from inventor struct and concatenate them for each id, like so:

Row     id      app_date    inventors   
1       id_1    01-15-2022  Steve, Ashley
2       id_2    03-16-2011  Pete, ^, Mary

Note custom filling for null value - which, to me, seems like it means I need to use ARRAY_TO_STRING specifically that supports this.

The closest example I found doesn't work with nulls. How can one do this?

1 Answer 1

1

Use below

SELECT * EXCEPT(inventor), 
  (SELECT STRING_AGG(IFNULL(name, '^'), ', ') FROM t.inventor) inventors
FROM sample t      

with output

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.