簡體   English   中英

BigQuery 中的 ROW 類型/構造函數

[英]ROW type/constructor in BigQuery

BigQuery 是否有ROW的概念,例如類似於MySQLPostgresOracleSnowflake 我知道它在執行INSERT... VALUES (...)時隱含地使用它,例如:

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

每個值都隱含為Inventory表的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);    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM