Skip to content

Instantly share code, notes, and snippets.

@vicenteg
Created August 22, 2017 13:04
Show Gist options
  • Save vicenteg/f757b5f8562812855f2804f538113adf to your computer and use it in GitHub Desktop.
Save vicenteg/f757b5f8562812855f2804f538113adf 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`.
#!/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