google-bigquery

Backquote usage in BigQuery for table names - UI vs API


When I try a query using the BigQuery UI like:

SELECT * FROM `mytable.mydataset.table`;

it works fine.

When I try the same thing using the API with a request like:

{
  "query": "SELECT * FROM `mytable.mydataset.table`"
}

I get the error:

Invalid project ID '`mytable`'. Project IDs must contain 6-63 lowercase letters, digits, or dashes. Some project IDs also include domain name separated by a colon. IDs must start with a letter and may not end with a dash.

Why? And how do I fix it?


Solution

  • Changing it to not use legacy SQL worked:

    {
      "query": "SELECT * FROM `mytable.mydataset.table`",
      "useLegacySql": false
    }