0

I am running a query that I plan on using multiple times. However when running this query the 'my-job1a' has to be different everytime so I was planning on making this go by the date time. Does anybody know how to implement the date time function for this?

from google.cloud import bigquery
client = bigquery.Client('dataworks-356fa')


query = query

dataset = client.dataset('FirebaseArchive')
table = dataset.table(name='test1')
tbl = dataset.table(name='test12')
job = client.run_async_query('my-job1a', query)
job.destination = tbl
job.write_disposition= 'WRITE_TRUNCATE'
job.begin()

1 Answer 1

1

i believe "my-job1a" is a constant string. and you want to change the string for new query.

import datetime
# "my-job1a" replace this with "my-job1a" + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

job = client.run_async_query("my-job1a-" + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), query)

this will change for each second . if you want in millisecond then change the strftime function parameter. if you don't want such a big string , then change strftime parameter as per your choice.

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

2 Comments

When I write this I get this error 'TypeError: datetime.datetime(2017, 7, 11, 16, 0, 28, 999204) is not JSON serializable'. This is the code i set it as a.strftime("%Y%m%d%H%M%S")
please check your code !! this issue is might be related to some other problem. @W. Stephens

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.