I created a job to run query in cloud in terraform and it run succesfully but job not done in clouds. biquery.tf
resource "google_bigquery_job" "user_data_job" {
job_id = "job_query_${random_id.random_job_id.hex}"
location = "US"
labels = {
"job_type" ="create_table"
}
query {
query = "CREATE TABLE myproject.shop45_dataset.user_data AS SELECT first_name, last_name, email,FROM myporject.shop45_dataset.shop_data"
destination_table {
project_id = google_bigquery_table.shop_table.project
dataset_id = google_bigquery_table.shop_table.dataset_id
table_id = google_bigquery_table.shop_table.table_id
}
allow_large_results = true
flatten_results = true
}
depends_on = [
google_bigquery_job.import_job
]
}
also i try different sql query
CREATE TABLE `user_data` AS SELECT first_name, last_name, email, FROM ${google_bigquery_table.shop_table.table_id}"
I want to create a table from shop_table table
My cloud log.
job_type: "create_table"
}
query: {
createDisposition: "CREATE_IF_NEEDED"
defaultDataset: {0}
destinationTable: {3}
query: "CREATE TABLE t-12-vm.shop45_dataset.user_data AS SELECT first_name, last_name, email,FROM t-12-vm.shop45_dataset.shop_data"
queryPriority: "QUERY_INTERACTIVE"
statementType: "QUERY_STATEMENT_TYPE_UNSPECIFIED"
writeDisposition: "WRITE_EMPTY"
}
}
jobName: {3}
jobStatistics: {3}
jobStatus: {
additionalErrors: [1]
error: {
code: 11
message: "Cannot set destination table in jobs with DDL statements"
}
state: "DONE"
}
}
}
}
Don't set the destination_table
property. It's conflicting with the query.
Alternatively, remove the CREATE TABLE AS
from query
and allow the results to land in the destination table and manage the DDL part explicitly.