BigQuery Syntax error: Unexpected string literal 'dataset.table' at [position]

Problem 🔍

The object names in Bigquery can optionally be enclosed in backticks ` (You can find this key below Esc button on your keyboard). Users confuse backticks with single quote and when they use single quote Bigquery throws this error

SELECT Id, Name FROM '93868086.ga_sessions_*'
Syntax error: Unexpected string literal 'dataset.table' at [1:244]

Solution 💡

Method #1: Replace the single quote ' with backticks ` 

You can find the ` backticks key below Esc button on your keyboard

FROM 'dataset.tablename'

to

FROM `dataset.tablename`

Method #2: Do not enclose the object names in single quotes

In the latest update, you can get rid of backticks as well and you can simply specify the projectname.datasetname.tablename, like shown below

FROM projectname.datasetname.tablename

Best Practice ⚡

  • Use a fully qualified object name wherever possible. eg. projectname.datasetname.tablename
  • Avoid using backticks on object names

victor

posted on 16 Feb 19

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds