Oops! used a reserved word to name a column

心已入冬 提交于 2020-02-03 03:18:44

问题


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!


回答1:


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.




回答2:


DOCS - CTRL-F "bracket" and it'll take you right to the paragraph in the docs.

This is multiple years late, but here is a link to the documentation for future reference, as per suggestion of Chris. I could not post it as a direct reply, but the question was marked answered long ago.



来源:https://stackoverflow.com/questions/18905842/oops-used-a-reserved-word-to-name-a-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!