Hi all,
I am using
https://github.com/googleapis/nodejs-bigquery
I want to create delete the table data and Insert into same table.
import { BigQuery } from '@google-cloud/bigquery';
async function runQuery_truncate_table() {
console.log(" this is truncate_table")
const query = 'TRUNCATE TABLE `ghistory`';
const options = {
query: query,
};
const [job] = await bigquery.createQueryJob(options);
console.log(`Job ${job.id} Deleted .`);
}
// main run
// let dt1 = await runQuery_truncate_table().catch(console.error);
// //setInterval(runQuerydelete_table, 1500);
async function main() {
await runQuery_truncate_table();
// await datainsert();
}
main();
client truncate run after the data insert. it was not happens all time,
Solved! Go to Solution.
Please try the below updated function:
import { BigQuery } from '@google-cloud/bigquery';
const bigquery = new BigQuery();
async function runQuery_truncate_table() {
console.log("This is truncate_table")
const query = 'TRUNCATE TABLE `your-project-id.your-dataset-id.ghistory`';
const options = {
query: query,
};
const [job] = await bigquery.createQueryJob(options);
await job.getQueryResults();
console.log(`Job ${job.id} executed .`);
}
async function main() {
await runQuery_truncate_table();
// await datainsert();
}
main();
Please try the below updated function:
import { BigQuery } from '@google-cloud/bigquery';
const bigquery = new BigQuery();
async function runQuery_truncate_table() {
console.log("This is truncate_table")
const query = 'TRUNCATE TABLE `your-project-id.your-dataset-id.ghistory`';
const options = {
query: query,
};
const [job] = await bigquery.createQueryJob(options);
await job.getQueryResults();
console.log(`Job ${job.id} executed .`);
}
async function main() {
await runQuery_truncate_table();
// await datainsert();
}
main();
@ms4446 Thanks lot's