-
-
Save karlarao/b5403383efb04e19c4d1460df14efe46 to your computer and use it in GitHub Desktop.
Shell script to extract the schema from an existing BigQuery table and output the schema in a format suitable for use with `bq mk`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z $1 ]; then | |
echo "Provide a BQ table spec, ideally fully qualified." | |
exit 1 | |
fi | |
if $(echo "" | jq .); then | |
bq --format json show $1 | jq -j '[.schema.fields[] | .name + ":" + .type] | join(",")' | |
else | |
echo "Please install jq." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment