Daniel Lee
Daniel Lee

Reputation: 8031

Accessing a column named Cast in Bigquery

I have a table and one of the columns is named CAST. How can I access this column. I've tried Select [Cast] AS cast_s FROM tablename without success, Can I use this name or must I reimport all my data into bigquery?

I know that cast is a function. This is the error message:

Error:

Encountered " "CAST" "Cast "" at line 10, column 63. Was expecting: < E O F > (EOF has no spaces, markdown makes it disappear)

Thanks.

Upvotes: 0

Views: 1711

Answers (2)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 173046

For BigQuery Legacy SQL you CAN use square brackets

SELECT [cast] as cast_s
FROM tablename

From documentation

You can use square brackets to escape reserved words so that you can use them as field name and aliases. For example, if you have a column named "prefix", which is a reserved word in BigQuery syntax, the queries referencing that field will fail with obscure error messages unless you escape it with square brackets:

SELECT [prefix] FROM ...

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270431

The lexical rules for BQ use backticks for this purpose:

select `cast` as cast_s
from tablename;

The documentation is here.

Upvotes: 2

Related Questions