I am getting a syntax error from the following query:
SELECT * FROM natural-engine-438716-p4.babynames.names_2014
I am new to SQL queries, and I am unsure how to resolve the table location containing a keyword. This is within BigQuery
The error code is the following: Syntax error: Unexpected keyword NATURAL at [2:6]
Any help would be greatly appreciated!
Hi @pbrendan85,
Welcome to Google Cloud Community!
Upon checking, the same question was asked in Stack Overflow in which the provided solution worked.
For Google Cloud Community Forum visibilty, here's the solution offered:
@easleyfixed wrote:
When searching for a table, you need to be careful about which characters that are used when naming. In the example you gave, you have this query :
SELECT * FROM natural-engine-438716-p4.babynames.names_2014
The dash character, among many others such as backslash, are used directly by MYSQL for commands, so when you try to use them inside of db and table names, they can throw erorrs like the one you have seen.
Some characters can be escaped or terminated by doubling up the character, and in other cases, you can do wrapping of the names in question to allow them to exist with the offending character.
You must use a backtick, this character ` found to the left of the 1 key usually on the keyboard. Wrap the db.table like this :
SELECT * FROM 'natural-engine-438716-p4.babynames.names_2014`
This should allow you to select that table without an issue.
Hope this helped!
Hi @pbrendan85 ,
In the bigquery for Query follow like below,
natural key word is reserved key might be so ensure to use `
Select * from `project_id.dataset_id.table_name`;