LoginSignup
8
1

More than 1 year has passed since last update.

BigQueryで絶対にクエリを実行できないVIEWを作る その1

Last updated at Posted at 2022-11-30

以下のようなカラム名の重複するクエリをBigQueryのWeb UIからVIEWとして登録するとどうなるでしょうか?

select 1 as hoge, 1 as hoge

スクリーンショット_2022-11-18_20_25_05.png

答え

VIEWは作成されるが、どのようにSELECTしても失敗するVIEWになる。

viewのスキーマ的には重複したカラム名が許されないようなので、片方の名前が hoge_1 になっています。

スクリーンショット 2022-11-18 20.26.09.png

試しに色々な方法でクエリを実行できるかどうか検証してみましょう。

select * from `<project_id>.<dataset_id>.ill_formed_view1`;
-- Duplicate column name 'hoge' in definition of view '<project_id>.<dataset_id>.ill_formed_view1'

select hoge from `<project_id>.<dataset_id>.ill_formed_view1`;
-- Column name hoge is ambiguous at [1:8]

select hoge_1 from `<project_id>.<dataset_id>.ill_formed_view1`;
-- Unrecognized name: hoge_1; Did you mean hoge? at [1:8]

select null from `<project_id>.<dataset_id>.ill_formed_view1`;
-- Duplicate column name 'hoge' in definition of view '<project_id>.<dataset_id>.ill_formed_view1'

select null from `<project_id>.<dataset_id>.ill_formed_view1` limit 0;
-- Duplicate column name 'hoge' in definition of view '<project_id>.<dataset_id>.ill_formed_view1'

どうやってもエラーになるようです。

ちなみに

Web UIではなく、CREATE VIEW文でこのようなVIEWを作ろうとするとエラーになります。

create view `<project_id>.<dataset_id>.ill_formed_view1` as
select 1 as hoge, 1 as hoge;
8
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
1