0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

BigQuery の schema ファイルからカラムすべてが含まれる select 文をつくるワンライナー

Last updated at Posted at 2024-11-21

要するに、bq show -schema の結果から、select 文を作りたいということ。
bq show -schema の結果が foo-table.json とする。

zsh で以下を実行

 target=foo-table.json; \
jq -r '.[].name' $target \
| xargs \
| gawk '{
    table = ENVIRON["target"]
    sub(/\.[^.]+$/, "", table)
    gsub(/ /, ", \n  ")
    print "SELECT \n  " $0 " \nFROM\n  " table "\n;"
}'

実行結果イメージ

SELECT
  col_a,
  col_b,
  col_c
FROM
  foo-table
;
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?