简体   繁体   English

BigQuery 中的 ROW 类型/构造函数

[英]ROW type/constructor in BigQuery

Does BigQuery have the concept of a ROW , for example, similar to MySQL or Postgres or Oracle or Snowflake ? BigQuery 是否有ROW的概念,例如类似于MySQLPostgresOracleSnowflake I know it sort of implicitly uses it when doing an INSERT... VALUES (...) , for example:我知道它在执行INSERT... VALUES (...)时隐含地使用它,例如:

INSERT dataset.Inventory (product, quantity)
VALUES('top load washer', 10),
      ('front load washer', 20)

Each of the values would be implicitly be a ROW type of the Inventory table, but is this construction allowed elsewhere in BigQuery?每个值都隐含为Inventory表的ROW类型,但在 BigQuery 的其他地方是否允许这种构造? Or is this a feature that doesn't exist in BQ?或者这是 BQ 中不存在的功能?

I think below is a simplest / naïve example of such constructor in BigQuery我认为下面是 BigQuery 中此类构造函数的最简单/天真的示例

with t1 as (
  select 'top load washer' product, 10 quantity, 'a' type, 'x' category union all
  select 'front load washer', 20, 'b', 'y' 
), t2 as (
  select 1 id, 'a' code, 'x' value union all
  select 2, 'd', 'z'
)
select *
from t1
where (type, category) = (select as struct code, value from t2 where id = 1)   

Besides using in simple queries, it can also be use in BQ scripts - for example (another simplistic example)除了在简单查询中使用外,它还可以在 BQ 脚本中使用——例如(另一个简单的例子)

declare type, category string;
create temp table t2 as (
  select 1 id, 'a' code, 'x' value union all
  select 2, 'd', 'z'
);    
set (type, category) = (select as struct code, value from t2 where id = 1);    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM