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.
-
are you bound to running your script from within Google Scripts API?Mikhail Berlyant– Mikhail Berlyant2018-04-12 18:33:04 +00:00Commented 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 bigqueryuser3853657– user38536572018-04-13 11:11:35 +00:00Commented Apr 13, 2018 at 11:11
2 Answers
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.
4 Comments
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