SQLをちょっと試したい時のUNNEST
都合良いデータが無いときはunion all
を繋げて複数行をテストデータ作ってたけど、unnest
を使えば短いコードでテストデータが作れる。
unnestを使ったSQL確認方法
select a, b
from
unnest([null, 1]) as a,
unnest(['x', 'y']) as b
-- SQL結果
| 行 | a | b |
| 1 | null| x |
| 2 | null| y |
| 3 | 1 | x |
| 4 | 1 | y |
-- 同じデータをunion allで作った場合
select a, b
from (
(select null as a)
union all (select 1 as a)
),
(
(select 'x' as b)
union all (select 'y' as b)
)