0

Is it possible to run a specific job from BigQuery calling it by its jobId from Google Scripts API instead of pasting the entire query? I would like to set up a trigger to run a job periodically, but I do not want to paste the entire query to Scripts API, because of error-prone and time consuming formatting. Update: Queries should be able to use temporary functions.

2
  • are you bound to running your script from within Google Scripts API? Commented Apr 12, 2018 at 18:33
  • i would very much like to do so, as I have encountered numerous problems with setting cron jobs for bigquery Commented Apr 13, 2018 at 11:11

2 Answers 2

2

No, you can't re-run a job like that using its id. But you could use the API to get the details of the job and pull the SQL from it i.e. https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/get

I'm not exactly sure why you can't just have the SQL in the script. That said, I'd just put the SQL in a view in BigQuery anyway, and call the view from your script.

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

4 Comments

I am trying to avoid having SQL in the script as some longer queries tend to have problems with formatting for the Google Scripts format and I constantly have problems with not being able to detect what exactly is wrong with the query because there is no way of debugging it without changing the formatting of the query.
You can put it in a view instead then
Yep, but I cannot save view with temporary functions :)
New information! Can you please update your original question with that?
0

a job is an instance of a query, so technically you can't run the same job multiple times. You can probably access the job details and fetch the query, but it would be much simpler to just create a new job with the given query.

I see that you want to avoid longer queries from running into formatting errors. if your job is only about reading things you then create views for the complicated queries and just trigger jobs that do Select * from view instead. This way you 1) have the query definitions easy to access, straight on the BQ UI and 2) don't run into formatting problems when assembling the job

2 Comments

I cannot save view with temporary functions which is a blocker for me.
This looks like you simply took my answer and reworded it slightly!

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.