LoginSignup
4
0

More than 1 year has passed since last update.

BigQueryのカラム名に予約語を使う方法

Last updated at Posted at 2022-12-14

以下のSQLはSyntax Errorになり実行できません。
カラム名にselectという予約語を使っているためです。

create table `<テーブル名>` (
  select int64,
  insert int64, 
  update int64,
  delete int64,
);

しかし、止むに止まれぬ事情でカラム名に予約語を使う必要が出た場合はどうすればよいでしょうか?

答え

カラム名をバッククォートで囲む。

create table `<テーブル名>` (
  `select` int64,
  `insert` int64,
  `update` int64,
  `delete` int64,
);

バッククォートで囲むことで予約語ではなくカラム名として認識されるようです。

スクリーンショット 2022-12-02 8.46.31.png

なお、このテーブルを参照するときにもカラム名をバッククォートで囲む必要があります。

select `select`, `insert`, `update`, `delete` from `<テーブル名>`
4
0
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
4
0