BigQuery error · Not found and location
Cannot read and write in different locations
The job reads data in one location and writes the result to a dataset in another, and a BigQuery job can't cross locations. Write to a dataset in the source's location, or move the data first with a dataset copy, replication or an export and load.
The error message
Cannot read and write in different locations: source: <source_location>, destination: <destination_location>
Causes
The destination dataset is in another location
A query with a destination table, CREATE TABLE ... AS SELECT, INSERT ... SELECT or a scheduled query reads US data and writes into an EU dataset, or the other way round. The source and destination in the message tell you which two locations clash.
A single region and a multi-region
us-east1 and US are different locations, as are europe-west1 and EU. Datasets created by different people or tools with different defaults are a common source of this mismatch.
A tool creates its own staging dataset or bucket
Dataflow and Beam pipelines, ETL connectors and BI tools create temporary datasets or Cloud Storage buckets. If those are created in a default location that differs from your data, the tool's jobs fail with this error.
How to fix it
1. Check both locations
Compare the dataset locations before changing anything. The query below lists datasets in one region; run it for each region you use.
SELECT schema_name, location
FROM `project`.`region-us`.INFORMATION_SCHEMA.SCHEMATA
ORDER BY schema_name;2. Write into a dataset in the source's location
Create a dataset next to the data and write the result there. A dataset's location can't be changed after creation, so create a new one if needed.
CREATE SCHEMA IF NOT EXISTS `project.reporting_us`
OPTIONS (location = 'US');
CREATE OR REPLACE TABLE `project.reporting_us.daily_orders` AS
SELECT order_date, COUNT(*) AS orders, SUM(amount) AS revenue
FROM `project.sales_us.orders`
GROUP BY order_date;3. Move the data, then query it
Copy the source dataset to the destination's location with the BigQuery Data Transfer Service dataset copy or cross-region replication, or export to a Cloud Storage bucket and load from it. Cross-region transfers and the extra copy of the data are billed, so move aggregated data when you can.
4. Fix the location of a tool's staging resources
Set the temporary dataset or bucket location in the tool's settings (for example the temp location of a Dataflow pipeline or the staging bucket of a connector) to the location of your BigQuery data.
How to prevent it
- Choose one location per environment and create datasets only with explicit
locationoptions in DDL or Terraform. - Keep cross-region data movement in one documented pipeline, so its transfer and storage cost is visible in Data FinOps reviews.
- Validate the destination dataset's location when a new scheduled query or connector is set up.
FAQ
Is a job that fails with this error billed?
No. The location check happens before the job reads data, so on-demand jobs aren't charged and no slots are used under editions.
Can I change the location of an existing BigQuery dataset?
No. Create a new dataset in the right location and copy or reload the tables into it, then repoint the jobs.
Why does the error name a location I never use?
The job or one of its staging resources was created with a default location. Check the job's location in its details, and the location of every dataset and bucket the tool uses, including temporary ones.
Related
SQL reference
All BigQuery error messages · What 50M daily events say about BigQuery failures
