1

Im trying to set the result of a query as an array. I can do this fine with only one column returned using the code below, but i get errors as soon as i try to add another column. How do i get multiple columns and store them in an array?

Thanks.

DECLARE my_array ARRAY<string>;

SET my_array = (
  SELECT ARRAY_AGG(value_1,value2)
  FROM `project.dataset.table`
  WHERE somthing = 'somthing'
);

1 Answer 1

2

Try below

DECLARE my_array ARRAY<STRUCT<value_1 STRING,value2 STRING>>;

SET my_array = (
  SELECT ARRAY_AGG(STRUCT(value_1,value2))
  FROM `project.dataset.table`
  WHERE somthing = 'somthing'
);
Sign up to request clarification or add additional context in comments.

1 Comment

ahh thank you! I had tried STRUCT but was not declaring the array correctly.

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.