繁体   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