I made a bigquery table with one column named "row" (no quotes)... doh! Now my sql won't compile if I reference that column:
SELECT row, etext FROM [hcd.hdctext] LIMIT 1; =ERROR"
I did not see "ROW" as a reserved word in GQL...
I saw that in some systems you can get around that problem with backticks :
SELECT `row`, etext FROM [hcd.hdctext] LIMIT 1;
(Using reserved words in column names)
Any way to do the same in bigquery? Otherwise I will have to reupload my 200M of data and start again. Seems like changing a field name would not be a big feature.. but I am naive about how the data is stored.
Thanks!
Using Keywords in Tables or Columns Generally, SQL developers advise against using reserved words. However, if you want (or need) to use a reserved word as a table or column name, you can place the respective identifier in special quotation marks, so-called backticks (` `), in the SQL statements.
In SQL, certain words are reserved. These are called Keywords or Reserved Words. These words cannot be used as identifiers i.e. as column names in SQL.
Within SQL certain words are reserved. You cannot use an SQL reserved word as an SQL identifier (such as the name for a table, a column, an AS alias, or other entity), unless: The word is delimited with double quotes ("word"), and. Delimited identifiers are supported.
To escape reserved keywords in SQL SELECT statements and in queries on views, enclose them in double quotes ('').
BigQuery Legacy SQL uses []
as quote chars. BigQuery Standard SQL uses backticks.
So, for Legacy SQL, just use
SELECT [row], etext from [hcd.hdctext]
If you want to rename it permanently, there isn't a way to do that currently, but you can rename it in a query and save the results... just use
SELECT [row] as newname, .... FROM [hcd.hdctext]
and specify 'allow large results' and a destination table name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With