LoginSignup
3
3

More than 3 years have passed since last update.

BigQueryでDDLの取得をする方法

Posted at

BigQueryで既存のテーブルの構成をコピーしたいので、DDL文を取る必要があった

create table 文は取れなそうだが、JSON形式では以下のコマンドで取得可能

bq show \
--schema \
--format=prettyjson \
project_id:dataset.table > path_to_file

取得したJSONファイルを元にテーブルを作るには以下のコマンド

bq mk --table project_id:dataset.table path_to_schema_file

テーブルの構成と一緒にデータもコピーしてよい場合は bq cp が便利

bq --location=location cp \
-a -f -n \
project_id:dataset.source_table \
project_id:dataset.destination_table

参考
https://cloud.google.com/bigquery/docs/schemas?hl=ja#specifying_a_json_schema_file

3
3
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
3
3