https://github.com/nacnudus/bq-parameterised
Demo parameterised queries in BigQueyr via the shell
https://github.com/nacnudus/bq-parameterised
Last synced: 2 months ago
JSON representation
Demo parameterised queries in BigQueyr via the shell
- Host: GitHub
- URL: https://github.com/nacnudus/bq-parameterised
- Owner: nacnudus
- Created: 2021-02-16T11:55:12.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-16T11:55:49.000Z (about 4 years ago)
- Last Synced: 2025-01-05T18:28:15.253Z (4 months ago)
- Language: Shell
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BigQuery parameterised queries at the command line
Run an SQL script in BigQuery, providing parameters at the command line,
including paramaterised table names, which aren't supported by the BigQuery API.```sh
bash query.sh --input_table=shakespeare --corpus="romeoandjuliet" --min_word_count=250
```## Requirements
Google's official BigQuery command-line tool,
[`bq`](https://cloud.google.com/bigquery/docs/bq-command-line-tool). This comes
in a collection of tools called the Google Cloud SDK.A service account credentials file. Mine is at
`$HOME/gds/govuk/modular_sql/secrets/my_credentials.json`## Configuration
```sh
gcloud auth activate-service-account --key-file=/path/to/my_credentials.json
gcloud config set project govuk-bigquery-analytics
```## References
* [Google's official BigQuery command-line tool, bq](https://cloud.google.com/bigquery/docs/bq-command-line-tool)
* [Running parameterised queries with `bq`](https://cloud.google.com/bigquery/docs/parameterized-queries#bq)
* [Parse command-line arguments in Bash](https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash)
* [Read files into variables in Bash](https://stackoverflow.com/a/10771857/937932)
* [Portable shell string substitution with variables](https://stackoverflow.com/a/22957485/937932)