2

After running below query

           SELECT ARRAY_TO_STRING( reporteeNames, '|') FROM 
         `appsflow-dev.PersonRequisition.ExternalNewHire`;

I am getting error

error

Schema

Fieldname                           Type    Mode

reporteeNames                       RECORD  REPEATED    
reporteeNames.reporteeTitle         STRING  NULLABLE    
reporteeNames.reporteeName          RECORD  NULLABLE    
reporteeNames.reporteeName.display  STRING  NULLABLE    
reporteeNames.reporteeName.value    STRING  NULLABLE

Please advise a solution specific to my schema.

4
  • You probably need to set the flag for using Standard SQL. Commented Jan 23, 2019 at 11:42
  • I'm already using Standard SQL. I checked my settings, the SQL Dialect choosen is "Standard". Commented Jan 23, 2019 at 12:58
  • @AbhishekBapna - can you clarify what exactly result you are expecting! Commented Jan 23, 2019 at 19:15
  • I was expecting the array to be converted into string to be displayed in a cell for each row. The method given in the answer posted below worked for me. Commented Jan 24, 2019 at 13:22

1 Answer 1

1

You need to unnest the array in order to select the field inside the struct:

SELECT
  (SELECT STRING_AGG(reporteeName, '|')
   FROM UNNEST(reporteeNames)) AS names
FROM `your-project`.dataset.table

See also the working with arrays documentation.

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.