1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
-- Example of "select as struct *" syntax.
select
some_table.foo_id,
array(
select as struct *
from another_table
where another_table.foo_id = some_table.foo_id
)
from another_table;
-- Example of "select as struct <<column list>>" syntax
select as struct
'1' as bb,
2 as aa;
select distinct as struct
'1' as bb,
2 as aa;
-- Example of explicitly building a struct in a select clause.
select
struct(
bar.bar_id as id,
bar.bar_name as bar
) as bar
from foo
left join bar on bar.foo_id = foo.foo_id;
-- Array of structs
SELECT
col_1,
col_2
FROM
UNNEST(ARRAY<STRUCT<col_1 STRING, col_2 STRING>>[
('hello','world'),
('hi', 'there')
]);
SELECT
STRUCT<int64>(5),
STRUCT<date>("2011-05-05"),
STRUCT<x int64, y string>(1, t.str_col),
STRUCT<int64>(int_col);
-- This is to test typeless struct fields are not mistakenly considered as
-- data types, see https://github.com/sqlfluff/sqlfluff/issues/3277
SELECT
STRUCT(
some_field,
some_other_field
) AS col
FROM table;
-- Empty STRUCT within TO_JSON
SELECT
TO_JSON(STRUCT()) AS col
FROM table;
SELECT (1*1, 2) IN (STRUCT(1 AS a, 2 AS b));
|