Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass query statement to bigquery in node.js environment

During the big query, the parameters of the function in the SQL statement I want to update the result of a sql statement by inserting it as @ variable name. However, there is no method to support node.js.

For python, there are methods like the following example. You can use the function's parameters as @ variable names.

query = "" "
SELECT word, word_count
FROM `bigquery-public-data.samples.shakespeare`
WHERE corpus = @ corpus
AND word_count> = @min_word_count
ORDER BY word_count DESC;"" "
query_params = [
bigquery.ScalarQueryParameter ('corpus', 'STRING', 'romeoandjuliet'),
bigquery.ScalarQueryParameter ('min_word_count', 'INT64', 250)]
job_config = bigquery.QueryJobConfig ()
job_config.query_parameters = query_params

related document: https://cloud.google.com/bigquery/docs/parameterized-queries#bigquery-query-params-python

I would like to ask for advice.

like image 828
Quack Avatar asked Oct 19 '25 02:10

Quack


1 Answers

BigQuery node.js client supports parameterized queries when you pass them with the params key in options. Just updated the docs to show this. Hope this helps!

Example:

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

const options = {
  query: sqlQuery,
  // Location must match that of the dataset(s) referenced in the query.
  location: 'US',
  params: {corpus: 'romeoandjuliet', min_word_count: 250},
};

// Run the query
const [rows] = await bigquery.query(options);
like image 169
Steffany Avatar answered Oct 21 '25 18:10

Steffany



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!