LoginSignup
1
0

More than 3 years have passed since last update.

BigQueryのbqコマンドメモ

Last updated at Posted at 2020-10-02

BigQueryをbqコマンドから操作できるので、よく自分が使うコマンドをメモします。

テーブルの詳細情報の確認

bq show my-project:samples.test_tbl

Last modified         Schema       Total Rows   Total Bytes   Expritation   Time Partitioning  Clustered Fields  Labels
---------------- ---------------- ------------ ------------- ------------- -------------------- ------------------ -------
12 Sep 10:20:30   |- id: string    12345678     91011121314  
                  |- col1: integer
                  |- col2: integer

データセット配下のテーブル一覧出力

bq ls -n 1000 --format=pretty bigquery-public-data:samples

+-----------------+-------+--------+-------------------+------------------+
| tableId         | Type  | Labels | Time Partitioning | Clustered Fields |
+-----------------+-------+--------+-------------------+------------------+
| github_nested   | TABLE |        |                   |                  |
| github_timeline | TABLE |        |                   |                  |
| gsod            | TABLE |        |                   |                  |
| natality        | TABLE |        |                   |                  |
| shakespeare     | TABLE |        |                   |                  |
| trigrams        | TABLE |        |                   |                  |
| wikipedia       | TABLE |        |                   |                  |
+-----------------+-------+--------+-------------------+------------------+
オプション 説明
--max_results または -n 出力結果の最大数を指定
デフォルトは50
--format 結果の出力形式を指定
pretty: フォーマットされたテーブル

クエリを実行する(例:テーブル作成)

bq query --nouse_legacy_sql 'create table if not exists `my-project:samples.test_tbl`'

クエリを実行する(例:SQLファイルの実行)

bq query --project my-project --use_legacy_sql=false "`cat sample.sql`"
オプション 説明
--nouse_legacy_sql
または
--use_legacy_sql=false
標準SQLクエリを使用
--use_legacy_sql レガシーSQLを使用

テーブルをコピーする

bq cp my-project:samples.test_tbl_a my-project:samples.test_tbl_b 

 
参考:https://cloud.google.com/bigquery/docs/reference/bq-cli-reference?hl=ja

1
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
1
0