The STRUCT expression in BigQuery allows you to create a structure or a nested field in your query result. This can be useful when you need to group multiple columns into a single value. The basic syntax for the STRUCT expression is as follows:
SELECT STRUCT([column1], [column2], ...) AS [struct_alias]
FROM [table_name];
SELECT STRUCT(first_name, second_name) AS full_name, salary
FROM freshers_in_table;
full_name column3
---------------------------- ------
{"first_name": "Sam", "second_name": "Peter"} "$35000"
{"first_name": "John", "second_name": "Williams"} "$45000"
...
SELECT STRUCT(column1 WITHIN struct_value AS field1, column2 WITHIN struct_value AS field2) AS struct_value, column3
FROM my_table;
struct_value column3
---------------------------- ------
{"field1": "value1", "field2": "value2"} "value3"
{"field1": "value4", "field2": "value5"} "value6"
...
BigQuery import urls to refer