• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Possible to create a multi-column table from unnest?

Resolved: Possible to create a multi-column table from unnest?

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Is it possible to do something like the following in BigQuery?
SELECT country, id FROM 
    -- possible to in-line this, with an array or struct even?
    [['us', 1], ['ca',2]] AS country (country, id)
Or perhaps there’s a better way to do it? Currently the way I’m doing it is the following, but I want to see if I can inline it into the FROM instead:
WITH country AS (
    SELECT 'us' AS country, 1 as id UNION ALL
    SELECT 'ca', 2
) 

Answer:

Another possible option would be to make it ARRAY<STRUCT<>> type. Consider below:
SELECT * FROM UNNEST([
  STRUCT('us' AS country, 1 AS id),
  STRUCT('ca',2)
]);

If you have better answer, please add a comment about this, thank you!

google-bigquery google-cloud-platform sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How do I use SetWindowText with Unicode in Win32 using PowerShell?

01/04/2023

Resolved: Shopware 400 Status Error “This value is too long. It should have 255 character or less.” When I Try Updating Database Table

01/04/2023

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.