BIGQUERY (HowTo): How do you escape a table or field name in BigQuery?

Knowledge Drop

Last tested: Jan 10, 2018
 

In BQ Standard SQL, you can escape names by enclosing it in backticks:

SELECT `schema.table`.`field` AS table1.field FROM public.`schema.table` AS table1

In BQ Legacy SQL, you can escape names by enclosing it in brackets:

SELECT [schema.table.field] AS table1.field FROM [project:schema.table] AS table1

In Legacy SQL, this is only relevant if you have dashes in the name, which would cause an error without the brackets.

Source: BigQuery documentation

Chat tip: Escaping the table name this way in the sql_table_name parameter can resolve errors like Aliases referenced in the from clause must refer to preceding scans 

This content is subject to limited support.                

Version history
Last update:
‎06-14-2021 06:16 PM
Updated by: