首页 > 解决方案 > 如何将 .jsonl 加载到雪花表变体中?

问题描述

如何将 .jsonl 作为雪花的 json 加载到表变体中

create or replace table sampleColors (v variant);

insert into
   sampleColors
   select
      parse_json(column1) as v
   from
   values
     ( '{r:255,g:12,b:0} {r:0,g:255,b:0} {r:0,g:0,b:255}')
    v;

select * from sampleColors;

Error parsing JSON: more than one document in the input

标签: snowflake-cloud-data-platformsnowflake-schemasnowflake-task

解决方案


如果您希望每个 RGB 值在其自己的行中,则需要使用如下表函数将 JSONL 拆分为每个 JSON 一行的表:

insert into
    sampleColors
select parse_json(VALUE) 
    from table(split_to_table( '{r:255,g:12,b:0} {r:0,g:255,b:0} {r:0,g:0,b:255} {c:0,m:1,y:1,k:0} {c:1,m:0,y:1,k:0} {c:1,m:1,y:0,k:0}', ' '));

推荐阅读