1

I'm aware of the fact that we can run parameterized queries in BQ CLI. Below is the working example taken from Big query documentation:

bq query --use_legacy_sql=False \
--parameter=corpus::romeoandjuliet \
--parameter=min_word_count:INT64:250 \
'SELECT word, word_count
FROM `bigquery-public-data.samples.shakespeare`
WHERE corpus = @corpus
AND word_count >= @min_word_count
ORDER BY word_count DESC;'

This way for every parameterized query we need to pass the parameters within the query execution statement itself. Suppose, if I have 'n' number of queries to be executed one after another. In that case is there any way to set the parameter values once. In all the following queries the same parameter values should be reflected. Any leads will be appreciated.

1 Answer 1

3

You can use an alias that incorporates the parameters, e.g.:

alias bqparams="bq query --use_legacy_sql=False --parameter=corpus::romeoandjuliet --parameter=min_word_count:INT64:250"

Now you can use this alias to run each query:

bqparams 'SELECT word, word_count
  FROM `bigquery-public-data.samples.shakespeare`
  WHERE corpus = @corpus
  AND word_count >= @min_word_count
  ORDER BY word_count DESC;'

It's okay not to reference all parameters in each query that you run.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.