Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oops! used a reserved word to name a column

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!

like image 574
wgw Avatar asked Sep 19 '13 22:09

wgw


People also ask

How do you use SQL reserved words as column names?

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.

Can I use MySQL keyword as column name?

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.

How do you use reserved words 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.

How do you avoid reserved words in SQL?

To escape reserved keywords in SQL SELECT statements and in queries on views, enclose them in double quotes ('').


1 Answers

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.

like image 152
Jordan Tigani Avatar answered Sep 20 '22 14:09

Jordan Tigani