I have a cloud function that uses bigquery client to make operations. Ultimately I'm looking to check if a row with an specific id exists so I built the following function (for now I'm just looking to make the request work and log the results):
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery({
projectId: 'myProjectID',
keyFilename: 'mykey.json'
});
await idExist('MyID--Ak2aRpL0','myProjectID.myDatasetID.myTableName')
async function idExist (id,table){
console.log('Checking if it exist')
const query = `SELECT * FROM \`${table}\` WHERE id='${id}'`;
const options = {
query: query,
location: table
}
const [job] = await bigquery.createQueryJob(options);
console.log(`Job '${job.id}' started.`);
const [rows] = await job.getQueryResults();
console.log('Resulted Rows:');
rows.forEach(row => console.log(row));
}
When I run this I get Error: Location projectID.datasetId.tableName does not support this operation. at new ApiError (/node_modules/@google-cloud/common/build/src/util.js:75:15)
Things I tried:
SELECT 1 AS TEST
and SELECT count(1) FROM myProjectID.myDatasetID.myTableName
with the same result.Notes:
await bigquery.dataset('datasetID').table('tableName').insert(myObject);
const result = await bigquery.query(query);
I would really appreciate some help/guidance on this issue. Let me know If I'm missing any helpful information.
Thanks!!
I followed the wrong tutorial and made a simple mistake. In the query options location
means the fisical location of the dataset not the location of the table, mine was US. So the following options fixed the issue:
const options = {
query: query,
location: 'US'
}