簡體   English   中英

使用 SQL 將 output 從視圖轉換為 json 和雪花數組的問題

[英]issues converting output from a view to json and array in snowflake using SQL

我是雪花的新手,並且已經使用 sql 從表中成功創建了一個視圖,但是在創建將整個表轉換為 Json 和數組的視圖時遇到問題

我的觀點

create or replace  view my_view as (
  select id, town, created_date, updated_at, array_construct( 
 object_construct('service','green','period', 
 object_construct('Type',type,'end_date', end_date)))Services
from demo
);

my_view output

ID 創建日期 更新時間 服務
123 莫達克 2024-03-29 2024-03-29 [{“服務”:“綠色”,“周期”:{“類型”:“確定”,“結束日期”:“2024-03-29 11:17:42.000”}}]

我的目標是從 my_view 創建兩個視圖,它們將執行以下操作:

  1. 將 my_view 轉換為 json
  2. 將 my_view 轉換為數組

以下代碼能夠將 my_view 轉換為 json 並成功排列

select array_agg(object_construct(*)) from my_view; 

select object_construct(*) from my_view; 

但是當我嘗試用它創建一個視圖時,我得到了錯誤

create or replace  view my_json as (
  select object_construct(*) from my_view
);

產生的錯誤

SQL compilation error: Missing column specification

表達式必須有別名:

create or replace  view my_json as (
  select object_construct(*) AS output from my_view
);

或者:

create or replace view my_json(output) as (
  select object_construct(*) from my_view
);

暫無
暫無

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

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