如何在BigQuery中查询名为“OR”的列?

时间:2022-08-24 15:24:36

We unfortunately have a table with a column that has been written with the field name of "OR".

遗憾的是,我们有一个表格,其中的列名称为“OR”。

If we try to query this table - "SELECT OR FROM etc." we get an error because OR is a reserved word.

如果我们尝试查询此表 - “SELECT OR FROM etc.”我们得到一个错误,因为OR是一个保留字。

How do we query that column using BigQuery's legacy SQL queries? (We need that column and not others.)

我们如何使用BigQuery的旧SQL查询查询该列? (我们需要那个专栏而不是其他专栏。)

We thought we could use "SELECT *" and BigQuery's "exclude" feature but isn't part of legacy SQL so we are unable to use it. Other ideas?

我们认为我们可以使用“SELECT *”和BigQuery的“排除”功能,但不是遗留SQL的一部分,所以我们无法使用它。其他想法?

2 个解决方案

#1


0  

We found another SO answer for this - except you need to do something additional to what they describe. You cannot just add brackets to the name - you also need to give it a new column name.

我们找到了另一个SO答案 - 除了你需要对他们描述的内容做一些额外的事情。您不能只为名称添加括号 - 您还需要为其指定新的列名。

The answer is to query like this:

答案是这样查询:

SELECT [OR] AS new_column_name FROM ...

#2


0  

I know that you're looking for an answer using legacy SQL (and you found one using the bracket syntax), but for future readers, or, and, etc. are valid column names for query results in standard SQL. The following query will not return an error, for instance:

我知道您正在寻找使用遗留SQL的答案(并且您使用括号语法找到了答案),但对于将来的读者,或者等等,是标准SQL中查询结果的有效列名。以下查询不会返回错误,例如:

WITH T AS (
  SELECT
    1 AS `or`,
    2 AS `and`
)
SELECT * FROM T;

#1


0  

We found another SO answer for this - except you need to do something additional to what they describe. You cannot just add brackets to the name - you also need to give it a new column name.

我们找到了另一个SO答案 - 除了你需要对他们描述的内容做一些额外的事情。您不能只为名称添加括号 - 您还需要为其指定新的列名。

The answer is to query like this:

答案是这样查询:

SELECT [OR] AS new_column_name FROM ...

#2


0  

I know that you're looking for an answer using legacy SQL (and you found one using the bracket syntax), but for future readers, or, and, etc. are valid column names for query results in standard SQL. The following query will not return an error, for instance:

我知道您正在寻找使用遗留SQL的答案(并且您使用括号语法找到了答案),但对于将来的读者,或者等等,是标准SQL中查询结果的有效列名。以下查询不会返回错误,例如:

WITH T AS (
  SELECT
    1 AS `or`,
    2 AS `and`
)
SELECT * FROM T;