BigQuery 中的行 type/constructor
ROW type/constructor in BigQuery
BigQuery 是否有 ROW
的概念,例如类似于 MySQL or Postgres or Oracle or Snowflake?我知道它在执行 INSERT ... VALUES (...)
时隐含地使用它,例如:
INSERT dataset.Inventory (product, quantity)
VALUES('top load washer', 10),
('front load washer', 20)
每个值都隐含地是 Inventory
table 的 ROW
类型,但 BigQuery 的其他地方是否允许这种构造?或者这是BQ中不存在的功能?
我认为下面是 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)
除了在简单的查询中使用,它也可以在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);
BigQuery 是否有 ROW
的概念,例如类似于 MySQL or Postgres or Oracle or Snowflake?我知道它在执行 INSERT ... VALUES (...)
时隐含地使用它,例如:
INSERT dataset.Inventory (product, quantity)
VALUES('top load washer', 10),
('front load washer', 20)
每个值都隐含地是 Inventory
table 的 ROW
类型,但 BigQuery 的其他地方是否允许这种构造?或者这是BQ中不存在的功能?
我认为下面是 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)
除了在简单的查询中使用,它也可以在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);