0

Hello everyone what I am trying to do is through a query insert data to a tableA(), once data is inserted into Table A then delete the newly inserted values in A, then write the response/output into Table B that I created.

Here is my python code :

client = bigquery.Client()
#This is Table B
table_id = "ntest.practice.btabletest"
#here is the table I am writing my deleted output to
job_config = bigquery.QueryJobConfig(destination=table_id)


sql2 ="""
   INSERT INTO `ntest.practice.atabletest`(%s) VALUES (%s);
   DELETE FROM `ntest.practice.atabletest`
   WHERE name = 'HEART'
"""%(columns_aaa,valueaaa)

query_job1 = client.query(sql2,job_config=job_config)  # Make an API request.
query_job1.result()  # Waits for query to finish
print("Query results loaded to the table {}".format(table_id))

Yet, I get an error code saying:

google.api_core.exceptions.BadRequest: 400 configuration.query.destinationTable cannot be set for scripts

Any thoughts on how to fix this error? I don't believe, that my query is wrong, nor my tables or values are incorrect.

1
  • Refer to official documentation, you should consider using Data Manipulation Language. Please, take a look for this Stackoverflow thread. Commented Feb 13, 2020 at 9:06

1 Answer 1

0

Although BigQuery scripting doesn't support destination table, it doesn't seems that you'll need it for your specific query.

DELETE query never writes any data to a destination table. You may work around it by sending INSERT first then DELETE, this way, destination table will "work" (I mean BigQuery won't complaint about it). But you're getting an empty table.

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

1 Comment

I seem to be running into a similar issue, and not quite sure how to resolve it: stackoverflow.com/questions/65590829/…

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.